How do I add meta tags?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: How do I add meta tags?

Post by AbleMods » Mon Aug 18, 2008 1:04 pm

hmmm that should have eliminated it altogether...now I'm not sure either.

I'll do some playing around and see what I can learn.....
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: How do I add meta tags?

Post by jmestep » Mon Aug 18, 2008 2:44 pm

I played around with it some this morning, but didn't get a complete solution.
In product.aspx, you can remove this line:
Page.Title = _Product.Name;
and then put your <title> tag in your meta head field for the product and it show up.
That still leaves you with two titles- the second one is "View Product" and it looks like that is pulled from the first line of Product.aspx where it says Title="View Product".
If you take that out, then you still have two titles, with the second one being blank.
Other than figuring out that it's not part of the BindMetaTags in the PageHelper,cs, that's as far as I got.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: How do I add meta tags?

Post by Brewhaus » Mon Aug 18, 2008 8:53 pm

Wow, I seem to have gotten everybody digging on this one! :lol:

Not a big deal- I have managed to get the title that I want for the home page, and only a single tag, by removing the title tag from the head section of the Home Page layout and entering it in the Default.aspx file. I was hoping to override for a few pages (basically pages that show as products, but are really used for information pages). But I guess that I can live with those titles if I have to.

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: How do I add meta tags?

Post by Brewhaus » Thu Aug 21, 2008 9:14 pm

Would there be a way to add at least our company name prior to the product / category name? Right now, all that gets incorporated into the title is the product / category name (eg. Big Dawg). It would still be better to entirely do away with the auto-generated title, even though it means having to add a title tag to every product / category via the Admin menu, but we will take what we can get. :)

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: How do I add meta tags?

Post by jmestep » Fri Aug 22, 2008 8:46 am

I was able to do that in the product.aspx by adding text to this line:
Page.Title = _Product.Name + " at xxx.Com";
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: How do I add meta tags?

Post by Brewhaus » Sat Aug 23, 2008 1:39 pm

That worked great. Now, how about the category pages? They do not use the same Page.Title code.

albatreeq
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 33
Joined: Sat Jul 19, 2008 11:14 am

Re: How do I add meta tags?

Post by albatreeq » Tue Sep 09, 2008 4:03 am

1. Be logged in as an admin that can edit pages
2. go to the store page you want to set meta tags for
3. toggle "edit page" in footer
4. observe what is being used as "active layout"
5. go to admin
6. go to website _> content and layout
7. locate the layout scriptet in use for the page
8. click the copy button, you will be taken to the edit screen for your copy
9. enter a name that is appropriate (e.g. HOME PAGE)
10. In the header field, enter your meta tags...
11. Click Save to create the new page layout (including meta header)
12. Return to the store page
13. toggle "edit page" in footer
14. set the layout to the one you created
15. Click OK to set the page to your new layout

I adopted this procedure to put meta tags in the header section of various pages. But the various copies which i created for every page gets mixed up. For eg. following files are created from the original Right Sidebar file
Right Sidebar_Batteries
Right Sidebar_Carry Cases
Right Sidebar_IPOD Accessories
Right Sidebar_Networking Devices
Right Sidebar_Projectors

When these files are saved in the respective pages, the batteries is showing carrycases file, networking devices is showing ipod accessories file and so on.

Please help.

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: How do I add meta tags?

Post by Brewhaus » Tue Sep 09, 2008 7:33 am

The problem is that adding a title to this section causes the category to have two title tags, which is a no-no with some search engines. Judy's solution worked great for product pages, but I do not see how we can do the same thing for the category pages. If anyone knows how to do this, please share. :)

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: How do I add meta tags?

Post by jmestep » Tue Sep 09, 2008 7:39 am

I had looked around in the files a while ago and couldn't figure out the category title issue- it didn't seem to be generated like the product meta tags were. I've got the source code now and it's on my list to research that. I'll post back if I find anything.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: How do I add meta tags?

Post by Brewhaus » Tue Sep 09, 2008 7:46 am

Much appreciated. I am sure that I am far from the only one that would like to make use of this information.

combra
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Thu Jul 31, 2008 7:09 pm

Re: How do I add meta tags?

Post by combra » Sat Sep 13, 2008 3:58 pm

heinscott wrote:You're right, Joe. Probably the only really important tag is the Title tag. Content, of course, is still very important, as well as high quality links from relevant sites. Can't hurt to get a little boost from meta keywords and decriptions, though, even though they are not weighted that heavily.

Here's a copy of my MetaTags.aspx code, for anyone who is interested.

Scott
Scott, Great post with the code! I'm pretty new at this, so what's the process to get the code you posted to work? Basically, where do I put it and what do I need to do to get it to work? Any help would be appreciated. Thanks.
AC 7.0.7 build 14600

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: How do I add meta tags?

Post by Brewhaus » Sun Sep 14, 2008 8:33 am

The Title tag is also what appears to show as the heading for a page in most search results, so it is important to have the company name show in the title. Changing the default home page and product pages seemed simple enough, but there is still no information on how to alter the title on category pages.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: How do I add meta tags?

Post by mazhar » Mon Sep 15, 2008 12:53 am

Scott, Great post with the code! I'm pretty new at this, so what's the process to get the code you posted to work? Basically, where do I put it and what do I need to do to get it to work? Any help would be appreciated. Thanks.
Create a new file MetaTags.aspx in the Admin/Products/ folder and put all the code from Scott's post into it and save it.

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: How do I add meta tags?

Post by Brewhaus » Mon Sep 15, 2008 7:31 am

Does this not create a second Title tag?

User avatar
ajasko
Lieutenant (LT)
Lieutenant (LT)
Posts: 53
Joined: Sun Sep 23, 2007 8:04 pm
Contact:

Re: How do I add meta tags?

Post by ajasko » Mon Sep 15, 2008 10:23 am

ablegeek wrote:Does anyone know how to get the meta-tags implemented? My web site is sinking on the search engine results because I don't have this implemented.
Thank you!
Although Meta-Tags do have their uses, they basically mean diddly-squat to the Search Engines nowadays. Google and Yahoo, and probably all the others for that matter, do not take them into account. This is because they were abused in the past and people just went crazy with keyword stuffing them, and they have no bearing to actual content quality or ratio on your webpages. I would worry more about keywords in your actual page content, links and the like. Your ranking dropping probably has nothing to do with a lack of meta-tags.

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: How do I add meta tags?

Post by Brewhaus » Sun Sep 21, 2008 1:56 pm

As we cannot seem to come up with any way to simply alter the auto-generated title tag for categories, we had entered a title tag in the description field for one of the categories and apparently missed removing it when we found that using two title tags can get you blacklisted by some search engines. We have been watching where we rank on a few search terms and have found that the page that does use two title tags ranks on the first page for both Google and MSN, and (high) on the second page for Yahoo.

I assume, then, that it is safe to say that the three major search engines do not get upset over the use of two title tags. Does anyone have any knowledge on whether or not this is the case? In other words, since we cannot find a way to have the category title tag add a couple of words of text automatically, is it a safe bet to say that we can go ahead with dual title tags on all category pages, and it will not harm our SEO efforts?

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: How do I add meta tags?

Post by jmestep » Sun Sep 21, 2008 2:35 pm

If I run WebCEO, it gives a warning that a page should not have two titles.
Anyway, I finally found where the category ones are generated. For example, in CategoryGrid2.ascx.cs, it is here:
Page.Title = _Category.Name;

on line 46.
(I don't know why it isn't standardized one way or the other)

I think it would be better to move it to the .aspx page like on the Product2.aspx, but put it up above the META head also. WebCEO always warns that the title should be first.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: How do I add meta tags?

Post by Brewhaus » Sun Sep 21, 2008 2:54 pm

Great- I have adjusted my ProductGrid page. Now, how would you suggest removing it from the .cs file and adding it directly to the aspx file... or is it worth it?

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: How do I add meta tags?

Post by jmestep » Mon Sep 22, 2008 8:39 am

To me it was worth it since that way the pages are consistent with the product pages. I just commented it out of the .cs file and added it to the .aspx file above the line that binds the meta tags so that it would be before them in the web page.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: How do I add meta tags?

Post by Brewhaus » Sun Sep 28, 2008 8:52 am

Before proceeding, I checked and even the Default page has the meta tags listed before the title. Should I change this so that the title shows before the meta tags? If so, I assume that I need to somehow adjust the default.aspx file (help here, please, as this file is different from the product and category files), and the category and product page files?
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

Re: How do I add meta tags?

Post by Mike718NY » Mon Mar 02, 2009 12:16 pm

ablegeek wrote:I finally figured it out. The <tile> tag should be added on the .aspx file found on the root. The other metatags are actually as HTML comments in the .htm file that's why I never noticed them.
<!--
<Description>
How Does It Work?
</Description>
<HeaderData>
<meta name="description" content="your description">
<meta name="keywords" content="keywords">
</HeaderData>
-->
If you put the <title> in the .htm file and also in the .aspx file you will end up with two titles ( as I initially did). My only complaint now is that the <title> tags shows under the <meta name="description" and <meta name="keywords" and as I remember the <title> tag should show on top of the described tags. I'm not sure if there is any price to pay for that from the SEO (seach engine optimization) point of view.
Ablegeek,
when you say "The <tile> tag should be added on the .aspx file found on the root.",
where exactly? I tried to add it but it doesn't work.

Also, I added this to the .htm file, but it displays in the <body> section:
<Description>
How Does It Work?
</Description>
<HeaderData>
....

Can I ask you what you did to get title and meta tags on the Default.aspx page? thanks

Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

Re: How do I add meta tags?

Post by Mike718NY » Mon Mar 02, 2009 3:27 pm

Ok, I'm totally lost here.
Has anyone sucessfully added <title> and <meta> tags to the Default.aspx?

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: How do I add meta tags?

Post by jmestep » Mon Mar 02, 2009 6:25 pm

Yes. Added to default.aspx page
<script runat="server">
protected override void Render(HtmlTextWriter writer)
{
string pageHtml = string.Empty;

using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
base.Render(hw);
pageHtml = sw.ToString();

int headStartIndex = pageHtml.IndexOf("<head");
int headEndIndex = pageHtml.IndexOf("</head>");
string headerPart = pageHtml.Substring(headStartIndex, ((headEndIndex + 7) - headStartIndex));

StringBuilder sb = new StringBuilder(headerPart);
sb.Replace("<link", "\r<link");
sb.Replace("<META", "\r<META");
sb.Replace("<style", "\r<style");
int sindex = headerPart.IndexOf("<title>");
int eindex = headerPart.IndexOf("</title>");
string titleTag = headerPart.Substring(sindex, (eindex + 8) - sindex);
string titleText = headerPart.Substring((sindex + 7), (eindex - (sindex + 7)));
titleText = titleText.Replace("\r", string.Empty);
titleText = titleText.Replace("\t", string.Empty);
titleText = titleText.Replace("\n", string.Empty);
titleText.Trim();
titleText = String.Format("\r<title>{0}</title>", titleText);
sb.Replace(titleTag, "");
sb.Replace("<Title>","\r<Title>");
sb.Replace("</head>", "\r</head>");
string newHeaderPart = sb.ToString();
pageHtml = pageHtml.Replace(headerPart, newHeaderPart);
hw.Close();
}
sw.Close();
}
writer.Write(pageHtml);
}

</script>
Got rid of this in <cb:ScripletPart............
Title="Home Page"
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

divers-supply
Ensign (ENS)
Ensign (ENS)
Posts: 20
Joined: Fri Nov 21, 2008 5:15 pm

Re: How do I add meta tags?

Post by divers-supply » Wed Apr 08, 2009 4:02 pm

Code: Select all

<%@ Page Language="C#" MasterPageFile="Product.master" Title="Meta Tags" Inherits="CommerceBuilder.Web.UI.AbleCommerceAdminPage" %>
<%@ Register Assembly="CommerceBuilder.Web" Namespace="CommerceBuilder.Web.UI.WebControls" TagPrefix="cb" %>
<%@ Register Assembly="ComponentArt.Web.UI" Namespace="ComponentArt.Web.UI" TagPrefix="ComponentArt" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">

    int _ProductId;
    Product _Product;
    
    protected void Page_Load()
    {
        if (!Page.IsPostBack)
        {
            Populate();
        }
    }

    protected void SaveHeader(Object s, EventArgs e)
    {
        _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
        _Product = ProductDataSource.Load(_ProductId);
        _Product.HtmlHead = HTMLBox.Text;
        _Product.Save();
        Populate();
    }

    protected void RegenerateHeader(Object s, EventArgs e)
    {
        String Header = "";
        Header += "<title>" + PageTitle.Text + "</title>" + Environment.NewLine;
        Header += "<meta name='description' content='" + MetaDescription.Text + "'>" + Environment.NewLine;
        Header += "<meta name='keywords' content='" + MetaKeywords.Text + "'>" + Environment.NewLine;
        HTMLBox.Text = Header;
    }

    protected void Populate()
    {
        _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
        _Product = ProductDataSource.Load(_ProductId);
        int titleStart;
        int titleEnd;
        int descStart;
        int descEnd;
        int keyStart;
        int keyEnd;
        String Header = "";
        String TitleTag = "";
        String MetaDesc = "";
        String MetaKey = "";
        Header = _Product.HtmlHead;
        if (Header.Length > 0)
        {
            titleStart = Header.IndexOf("<title>") + 7;
            titleEnd = Header.IndexOf("</title>");
            if (titleStart > 0 && titleEnd > 0 && titleEnd > titleStart)
                TitleTag = Header.Substring(titleStart, titleEnd - titleStart);
            descStart = Header.IndexOf("<meta name='description' content='") + 34;
            descEnd = Header.IndexOf("'>", descStart);
            if (descStart > 0 && descEnd > 0 && descEnd > descStart)
                MetaDesc = Header.Substring(descStart, descEnd - descStart);
            keyStart = Header.IndexOf("<meta name='keywords' content='") + 31;
            keyEnd = Header.IndexOf("'>", keyStart);
            if (keyStart > 0 && keyEnd > 0 && keyEnd > keyStart)
                MetaKey = Header.Substring(keyStart, keyEnd - keyStart);
        }
        HTMLBox.Text = Header;
        PageTitle.Text = TitleTag;
        MetaDescription.Text = MetaDesc;
        MetaKeywords.Text = MetaKey; 
    }
    
    

</script>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<div class="pageHeader">
    <div class="caption">
        <h1><asp:Localize ID="Localize1" runat="server" Text="Meta Tags"></asp:Localize></h1>
    </div>
<div class="Content" style="padding:40px; border:1px solid blue;">
    <table width="90%">
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="HTMLBoxLabel" runat="server" Text="HTML Header"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="HTMLBox" TextMode="MultiLine" runat="server" Columns="100" Height="100"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="TitleLabel" runat="server" Text="Title Tags"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="PageTitle" runat="server" Columns="100" Height="20"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="MetaDescriptionLabel" runat="server" Text="Meta Description"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="MetaDescription" runat="server" Columns="100" Height="20"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="MetaKeywordsLabel" runat="server" Text="Meta Keywords"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="MetaKeywords" runat="server" Columns="100" Height="20"></asp:TextBox>
            </td>
        </tr>
    </table>
    <center>
        <asp:Button ID="Regenerate" Text="Regenerate Header" runat="server" OnClick="RegenerateHeader" />
        &nbsp;&nbsp;
        <asp:Button ID="SaveIt" Text="Save" runat="server" OnClick="SaveHeader" />
    </center>
</div>
  
</asp:Content>
I added the code that Scott listed and now my generated meta tags are missing double quotes they all have single quotes isn't this wrong?
<title></title>
<meta name='description' content='Description'>
<meta name='keywords' content='Keywords'>

It should be:

<title></title>
<meta name="description" content="Description">
<meta name="keywords" content="Keywords">

am I missing something?

User avatar
gio50000
Commander (CMDR)
Commander (CMDR)
Posts: 123
Joined: Mon Feb 18, 2008 12:51 pm
Location: Orlando, FL
Contact:

Re: How do I add meta tags?

Post by gio50000 » Sun Jun 21, 2009 7:53 pm

I found the easiest way to modify the content in the title tags was to edit the code example in red.

<script runat="server">
protected override void Render(HtmlTextWriter writer)
{
string pageHtml = string.Empty;

using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
base.Render(hw);
pageHtml = sw.ToString();

if (pageHtml.Contains("<head") && pageHtml.Contains("</head>"))
{
int headStartIndex = pageHtml.IndexOf("<head");
int headEndIndex = pageHtml.IndexOf("</head>");

string headerPart = pageHtml.Substring(headStartIndex, ((headEndIndex + 7) - headStartIndex));

StringBuilder sb = new StringBuilder(headerPart);
sb.Replace("<link", "\r<link");
sb.Replace("<META", "\r<META");
sb.Replace("<style", "\r<style");

int sindex = headerPart.IndexOf("<title>");
int eindex = headerPart.IndexOf("</title>");
string titleTag = headerPart.Substring(sindex, (eindex + 8) - sindex);
string titleText = headerPart.Substring((sindex + 7), (eindex - (sindex + 7)));
titleText = titleText.Replace("\r", string.Empty);
titleText = titleText.Replace("\t", string.Empty);
titleText = titleText.Replace("\n", string.Empty);
titleText.Trim();
titleText = String.Format("\r<title>{0} | Your page details here</title>\r", titleText);

int firstMetaIndex = sb.ToString().IndexOf("<META", 0, sb.Length, StringComparison.InvariantCultureIgnoreCase);
if (firstMetaIndex > -1)
{
sb.Replace(titleTag, string.Empty);
sb.Insert(firstMetaIndex, titleText);
}
else
{
sb.Replace(titleTag, titleText);
}
sb.Replace("</head>", "\r</head>");
string newHeaderPart = sb.ToString();
pageHtml = pageHtml.Replace(headerPart, newHeaderPart);
}
hw.Close();
}
sw.Close();
}
writer.Write(pageHtml);
}
</script>
Thank you,
Gio

Post Reply