How to enable default seo tags only to home page?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 年 前
Everything works fine. Perhaps you did something wrong or opened some other page. These extensions methods are also used on the product/category/manufacturer details pages and work just fine.
11 年 前
hi i achieved this by making some changes in the following files

0) Presentation/Nop.Web/Views/Home/index.cshtml
1) Presentation/Nop.Web/Views/Shared/_Rool.Head.cshtml
2) Presentation/Nop.Web.Framework/UI/LayoutExtension.cs
3) Presentation/Nop.Web.Framework/UI/IPageTitleBuilder.cs
4) Presentation/Nop.Web.Framework/UI/PageTitleBuilder.cs

changes in 0) Presentation/Nop.Web/Views/Home/index.cshtml


@{
   ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_ColumnsThree.cshtml";
}


changes in 1) Presentation/Nop.Web/Views/Shared/_Rool.Head.cshtml

modify after the head tag.
 

@{
        var flag = false;
        if (ViewData.ContainsKey("title"))
        {
            if (ViewData["title"] == "Index")  // write your logic here for some other pages.
            {
                flag = true;
            }
        }
    }

    <title>@Html.NopTitle(flag)</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <meta name="description" content="@(Html.NopMetaDescription(flag))" />
    <meta name="keywords" content="@(Html.NopMetaKeywords(flag))" />


changes in 2) Presentation/Nop.Web.Framework/UI/LayoutExtension.cs

added new parameter bool addDefaultDescription,

  public static MvcHtmlString NopMetaDescription(this HtmlHelper html, bool addDefaultDescription, params string[] parts)
        {
            var pageTitleBuilder = EngineContext.Current.Resolve<IPageTitleBuilder>();
            html.AppendMetaDescriptionParts(parts);
            return MvcHtmlString.Create(html.Encode(pageTitleBuilder.GenerateMetaDescription(addDefaultDescription)));
        }

do the same for NopMetaKeywords method too.


changes in 3) Presentation/Nop.Web.Framework/UI/IPageTitleBuilder.cs


  string GenerateMetaDescription(bool addDefaultDescription);
  string GenerateMetaKeywords(bool addDefaultKeywords);



changes in 4) Presentation/Nop.Web.Framework/UI/PageTitleBuilder.cs

public string GenerateMetaDescription(bool addDefaultDescription)
        {
            var metaDescription = string.Join(", ", _metaDescriptionParts.AsEnumerable().Reverse().ToArray());
            var result = string.Empty;
            if (addDefaultDescription)
                result = !String.IsNullOrEmpty(metaDescription) ? metaDescription : _seoSettings.DefaultMetaDescription;
            else
                result = !String.IsNullOrEmpty(metaDescription) ? metaDescription : string.Empty;

            return result;
        }

do the same for GenerateMetaKeywords method too.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.