homepage Welcome to WebmasterWorld Guest from 54.167.238.60
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

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




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

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?

 

rocknbil




msg:4420020
 4:25 pm on Feb 21, 2012 (gmt 0)

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
}

httpwebwitch




msg:4420022
 4:31 pm on Feb 21, 2012 (gmt 0)

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.

ThatsBoBo




msg:4420155
 9:00 pm on Feb 21, 2012 (gmt 0)

Hi guys,

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

Thanks for the help.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved