Meta Tags only on home page

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 anni tempo fa
Hi all,

I want to put meta tags only on the home page of my website. Can anyone tell me how to do it. The meta tags should not be seen on other pages of the website. Please explain me with an example too.
6 anni tempo fa
Sachin2018 wrote:
Hi all,

I want to put meta tags only on the home page of my website. Can anyone tell me how to do it. The meta tags should not be seen on other pages of the website. Please explain me with an example too.

regards,
Sachin Tripathi


On /Views/Shared/_Root.Head.cshtml

Find this code:

    <meta name="description" content="@(Html.NopMetaDescription())" />
    <meta name="keywords" content="@(Html.NopMetaKeywords())" />

You need to use conditional code to show these lines only if the visitor is currently viewing the home page, so use the PATH_INFO server variable:

Change this:

    <meta name="description" content="@(Html.NopMetaDescription())" />
    <meta name="keywords" content="@(Html.NopMetaKeywords())" />


..to this:

string currentpage=HttpContext.Current.Request.ServerVariables["PATH_INFO"];

if (currentpage == "/") {
    <meta name="description" content="@(Html.NopMetaDescription())" />
    <meta name="keywords" content="@(Html.NopMetaKeywords())" />
}


Doing it this way, you will only have meta tags on your home page, and you can define them in the admin >> Configuration >> Settings >> General & Miscellaneous Settings >> SEO screen.

Or maybe you are saying that you want DIFFERENT meta tags on the home page, but you do still want meta tags on all other pages???

If so, then do it like this:
string currentpage=HttpContext.Current.Request.ServerVariables["PATH_INFO"];

if (currentpage == "/") {
    <meta name="description" content="This is the special meta description only for home page" />
    <meta name="keywords" content="These, are, the, special, meta, keywords, for, only, home, page" />
}
else
{
    <meta name="description" content="@(Html.NopMetaDescription())" />
    <meta name="keywords" content="@(Html.NopMetaKeywords())" />
}
6 anni tempo fa
Thanks embryo, works great!!!
6 anni tempo fa
Wouldn't it just be easier to use the SEO information from the "HomePageText" topic?  Is this info not used anywhere?
5 anni tempo fa
The problem is that it appears on all the pages without any meta tags and ruins your SEO efforts.
4 anni tempo fa
Hi,

I tried but it is triggering an error from my side.

I tried this:

@string currentpage=HttpContext.Current.Request.ServerVariables["PATH_INFO"];

@if (currentpage == "/") {
    <meta name="description" content="This is the special meta description only for home page" />
    <meta name="keywords" content="These, are, the, special, meta, keywords, for, only, home, page" />
}
@else
{
    <meta name="description" content="@(Html.NopMetaDescription())" />
    <meta name="keywords" content="@(Html.NopMetaKeywords())" />
}

Please note that if I do not use "@", then the logic takes it as plain HTML.

Any help to how should be the exact code please?

Thank you in advance!
2 anni tempo fa
Nopcommerce should give an option to add additional meta tags or specific meta tags which related to specific product or page in text box like they gave in admin > configuration > settings > general setting, there is a text box for additional meta tags, which display on every page.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.