Welcome to WebmasterWorld Guest from 54.167.157.247

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Meta tags to show ONLY in <head> of site homepage

   
4:15 pm on Feb 21, 2012 (gmt 0)

5+ Year Member



Hi everyone,

So, I have some Facebook meta-tags that I'd like to show ONLY in the <head> of my website's homepage and NOT on any other page. It is a SQL php driven site that uses a small, unknown CMS. I'm adding these headers so users can "like" my homepage and so that Facebook will consider the homepage as my "facebook page".

I'm trying this:


<?php
if (mysite.com) echo '
<meta property="og:title" content="mysite.com" />
<meta property="og:type" content="website" />
<meta property="og:url" content="http://mysite.com" />
<meta property="og:image" content="http://mysite.com/uploads/1327767957.jpg" />
<meta property="og:site_name" content="mysite.com" />
<meta property="og:description"
content="This is what we do. Blah blah blah." />
<meta property="fb:admins" content="0000001" /> ';
?>


The problem is that all of my deeper pages also contain mysite.com in the url, so the if statement makes the meta-tags display in the <head> on all pages of the site, not just the homepage.

Any idea how I can rework this to get the meta-tags to only display on the homepage of this site?
4:25 pm on Feb 21, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



That would largely depend on the CMS and it's handling of templates, I would think. isn't there some hook in it to determine "main page"?

if (page=='home') {
// output these tags
}
4:31 pm on Feb 21, 2012 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



rocknbil is right; you'll need an "if".

try something like this

if ($_SERVER['REQUEST_URI'] == "/" || $_SERVER['REQUEST_URI'] == "/index.php"){
// yadda yadda
}

mind you this might not work if the CMS uses a funny URL scheme.

to figure this out, do:

print_r($_SERVER);

look at what is output by that. One of the variables there will likely be able to detect if the page being requested is the home page, or something else.
9:00 pm on Feb 21, 2012 (gmt 0)

5+ Year Member



Hi guys,

That actually works perfectly! I changed my if statement to look for / and bingo!

Thanks for the help.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month