Doing some SEO work on our website and trying to configure the page titles. It seems the logic is off or I am just misunderstanding the intent.

The settings involved are:

General Settings > Default Page Title
General Settings > Page title SEO adjustment
Store> Store Name


I'd think, that
General Settings > Default Page Title
would only be applied IF the page's configured SEO Title was blank. So this would include the home page, since there is no way to set its Title. And then any category, product pages where you leave the page title setting blank.

Then, the Store Name would ALWAYS be inserted (as there is no True/False setting for this, but probably should be) but where it should be inserted is set by
General Settings > Page title SEO adjustment
, i.e. either before or after the page title (which has been set thus far from the logic above (from product config or Default Page Title).

But that is not happening. In fact, it doesn't look like the Store Name comes into play at all, even though the comments state as much and the setting name indicates it will. There is no reference to Store Name in the code itself that I can see (unless it's obfuscated under some other name).

Source

public virtual string GenerateTitle(bool addDefaultTitle)
        {
            var result = "";
            var specificTitle = string.Join(_seoSettings.PageTitleSeparator, _titleParts.AsEnumerable().Reverse().ToArray());
            if (!string.IsNullOrEmpty(specificTitle))
            {
                if (addDefaultTitle)
                {
                    //store name + page title
                    switch (_seoSettings.PageTitleSeoAdjustment)
                    {
                        case PageTitleSeoAdjustment.PagenameAfterStorename:
                            {
                                result = string.Join(_seoSettings.PageTitleSeparator, _seoSettings.DefaultTitle, specificTitle);
                            }
                            break;
                        case PageTitleSeoAdjustment.StorenameAfterPagename:
                        default:
                            {
                                result = string.Join(_seoSettings.PageTitleSeparator, specificTitle, _seoSettings.DefaultTitle);
                            }
                            break;
                            
                    }
                }
                else
                {
                    //page title only
                    result = specificTitle;
                }
            }
            else
            {
                //store name only
                result = _seoSettings.DefaultTitle;
            }
            return result;
        }



This code is saying:
1.) If the page's configured title is blank, add the Default Title (though comment states
//store name only
, which it is not doing...it is not putting the store name, but rather the Default Title from settings....this is OK, but comment is wrong

2.) Only if a page specific title has been configured, and if the
addDefaultTitle
was passed in as true (which by default it always is), then and only then, it adds the
Default Page Title
from settings in a position as determined by the
General Settings > Page title SEO adjustment
setting.


So changes I see that would need to be made:

1.) The
bool addDefaultTitle
parameter of
public virtual string GenerateTitle(bool addDefaultTitle)
should be renamed to
bool addStoreName
to more accurately reflect its intent. Or for maximum configurability, leave it as is, but have it determine if to show the Default Page Title in the event that the configured page title is blank. Then add an additional parameter for
addStoreName
.

2.) Always include Store Name in title (or if from prior point, you add a new param so that this is param driven), but if before or after page title to be determined by the
General Settings > Page title SEO adjustment
setting


Here is suggested code change...and adding the
addStoreName
as a parameter for maximum configurability (although even more desirable would be to have this come from the Settings. Change
General Settings > Page title SEO adjustment
to have an additional value of
Do Not Add Store Name to Title
.


public static MvcHtmlString NopTitle(this HtmlHelper html, bool addDefaultTitle = true, bool addStoreName = true, string part = "")
        {
            var pageHeadBuilder = EngineContext.Current.Resolve<IPageHeadBuilder>();
            html.AppendTitleParts(part);
            return MvcHtmlString.Create(html.Encode(pageHeadBuilder.GenerateTitle(addDefaultTitle, addStoreName)));
        }

public virtual string GenerateTitle(bool addDefaultTitle, bool addStoreName)
        {
            var result = "";
            result = string.Join(_seoSettings.PageTitleSeparator, _titleParts.AsEnumerable().Reverse().ToArray());
            
            //If title is blank, add Default Page Title from settings            
            if (string.IsNullOrEmpty(result) && addDefaultTitle)
            {
                //add default page title from settings
                result = _seoSettings.DefaultTitle;
                
            }

            //Add Store Name to Title

            if (addStoreName)
            {
                //store name + page title
                switch (_seoSettings.PageTitleSeoAdjustment)
                {
                    case PageTitleSeoAdjustment.PagenameAfterStorename:
                        {
                            result = string.Join(_seoSettings.PageTitleSeparator, _store.StoreName, result);
                        }
                        break;
                    case PageTitleSeoAdjustment.StorenameAfterPagename:
                    default:
                        {
                            result = string.Join(_seoSettings.PageTitleSeparator, result, _store.StoreName);
                        }
                        break;                            
                }
            }

            return result;
        }


Thoughts?