Page 1 of 1

Meta tag code

Posted: Fri Mar 27, 2015 7:03 pm
by grgalex
Does anyone know if there is an easy way of making category titles populate the meta description and meta keyword fields automatically.
Thanks in advanced :D

Re: Meta tag code

Posted: Sun Mar 29, 2015 9:05 am
by Katie
Can you be more specific? What version of AbleCommerce are you using?

There should be a title field available for categories. I believe the feature was added to Gold R6 in Sept. 2013.

I'm not sure it would be advisable to populate this with your meta description and/or keywords since the title has it's own requirements, and it is different than meta info.

There is lots of great info that you can find on SEO. Here is one page that has some basic requirements for the Title field.

http://searchenginewatch.com/sew/how-to ... lden-rules#

Re: Meta tag code

Posted: Tue Mar 31, 2015 9:11 am
by grgalex
Running Gold R10 Responsive. When working with categories if you leave the page title field empty it will automatically populate the meta title by using the name. Obviously there is code for this to be done and my question is if there is already code that auto populates the meta title from the page name should it not be easy to add some code to populate the meta description and meta keywords from the page name as well. I have over 20000 categories and cannot imagine doing each one individually. As a matter of fact I had paid for a program several years ago for ac7 that did just that but does not work with gold. If not, could you point me in the direction of where the code is that currently does the above mentioned function.
Thanks :D

Re: Meta tag code

Posted: Tue Mar 31, 2015 9:20 am
by rmaweb
Hello grgalex,

If you go to Website/App_Code/PageHelper.cs and go to the BindMetaTags() function, you should be able to find what you need to get started.

Re: Meta tag code

Posted: Fri Apr 10, 2015 2:50 am
by nadeem
Are you able to achieve your desired goal? This is super easy to make it work as rmaweb suggested. You just need to locate the following code inside BindMetaTags() function:

Code: Select all

if (!string.IsNullOrEmpty(catalogObject.MetaDescription))
{
   htmlHead.Append(Environment.NewLine);
   htmlHead.Append(string.Format("<meta name=\"description\" content=\"{0}\" />", HttpUtility.HtmlEncode(catalogObject.MetaDescription)));
}

if (!string.IsNullOrEmpty(catalogObject.MetaKeywords))
{
    htmlHead.Append(Environment.NewLine);
    htmlHead.Append(string.Format("<meta name=\"keywords\" content=\"{0}\" />", HttpUtility.HtmlEncode(catalogObject.MetaKeywords)));
}
and replace with

Code: Select all

if (catalogObject.CatalogNodeType == CatalogNodeType.Category)
{
if (!string.IsNullOrEmpty(catalogObject.MetaDescription))
{
    htmlHead.Append(Environment.NewLine);
    htmlHead.Append(string.Format("<meta name=\"description\" content=\"{0}\" />", HttpUtility.HtmlEncode(catalogObject.MetaDescription)));
}
else 
{
    htmlHead.Append(Environment.NewLine);
    htmlHead.Append(string.Format("<meta name=\"description\" content=\"{0}\" />", HttpUtility.HtmlEncode(catalogObject.Name)));
}

if (!string.IsNullOrEmpty(catalogObject.MetaKeywords))
{
    htmlHead.Append(Environment.NewLine);
    htmlHead.Append(string.Format("<meta name=\"keywords\" content=\"{0}\" />", HttpUtility.HtmlEncode(catalogObject.MetaKeywords)));
}
else
{
    htmlHead.Append(Environment.NewLine);
    htmlHead.Append(string.Format("<meta name=\"keywords\" content=\"{0}\" />", HttpUtility.HtmlEncode(catalogObject.Name)));
}
}
else
{
if (!string.IsNullOrEmpty(catalogObject.MetaDescription))
{
   htmlHead.Append(Environment.NewLine);
   htmlHead.Append(string.Format("<meta name=\"description\" content=\"{0}\" />", HttpUtility.HtmlEncode(catalogObject.MetaDescription)));
}

if (!string.IsNullOrEmpty(catalogObject.MetaKeywords))
{
    htmlHead.Append(Environment.NewLine);
    htmlHead.Append(string.Format("<meta name=\"keywords\" content=\"{0}\" />", HttpUtility.HtmlEncode(catalogObject.MetaKeywords)));
}
}
Edit: Wrapped the code inside if...else to make it specific to the category objects.
This should work the way you want it.