Folks, since my site has gotten fairly popular I have people who want to advertise on the home page. The problem is that I didn’t know of a good method of embedding Ads that only show up on the home page and don’t appear site wide. (And not in the sidebar.)
I needed to employ a little PHP trickery in order to get this to work and I figured I’d share the methodology in case anyone else wanted to do this, or had a better idea as to how to pull it off.
In my case what I did was edit the Index.php file and added the following code to the bottom of the page inside the loop:
EDIT: Thanks to Storm for dropping me a comment with an even simpler method which came from Douglas Karr. Here it is:
<?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>
PLACE ADVERTISEMENT HERE.
<?php } ?>
What this does is causes the ads to appear on the Homepage, but not on any of the other Category or Archive “pages”.
Thanks for this tip mate… Now i am going to decorate my homepage with different stuffs :)
I’m grateful for sharing such a simple method of putting ads on homepage only.
I realized that this doesn’t work with Genesis framework, though it’s fine with other themes.
it is easy to edit, thanks
Wow Awesome Tip
Thanks John P
Thank you, I really appreciate it.
Just been trying loads of different things that weren’t working, at last you had the solution and all good now! Thanks a lot
thanks, love it! Very helpful tutorial!
thanks
Thanks for that, you’re a life saver. This just saved me stuffing around trying to figure it out myself.
Thanks! This works if I want one link on the homepage only.
What if I want a second and a third link? just below the first one. Home page only.
Tried to modify the code but only the first link is showing. Any help would be greatly appreciated. Thanks again!
How do you get this to show up just before the footer and below all of the posts on the front page? I can only seem to get it to work below the first post. Thanks.
Thanks! I’ve looked for code snippits like this for years. Every now and then I get paid for homepage links but don’t know a way to show them just on the homepage. This is the first time your site has come up as the top result and I’m glad it did.
Thanks! You got me out of a jam!!
Thanks a lot. Ii am a newbie who’s just starting out. I really appreciate the help in getting this done. Once again, Thank you very much.
Thanks for posting the elegant code that allows you to only display particular content on the wordpress homepage. I was racking my brain all afternoon trying to figure out a way to do this, then I stumbled upon your site and it made my night! Thanks!
Thanks for the help with the code. I have however some trouble with my requested advert as it needs to be incontent.
for example: A
anchor bit of blurb here
The bit of blurb at the end is coming up fine, but I can’t seem to workout how to get the ‘A’ to appear before the link..
Any help would be great..
I have bookmarked your site, very helpful indeed, thanks
It works like a charm, thanks for your tutorial.
Thanks mate. It will help me to monetize my site well.
Ha! – the perfect solution to an issue I had with one of my sites! If only I’d thought to Google it earlier, instead of wasting my time *not* working out how to do it…
Definitely linking you from my blog on the next update
Thanks a lot!
I loved this piece of code as I was able to drop it into a footer which is where I wanted the string of ads to show. This is great for companies that do a php string where they’re pulling from their server and dropping text into your page every time someone signs up for an ad. Wooohooo! Now ads only on the front page. Nice coding. Thanks for making it available.
thanks very very much!!! i googled about this by typing ‘ads on homepage only’ and your blog’s at the top! so thanks for posting about this code..
Thanks for the code.
Happy I can find your post on it.
Really helpful.
Happy that I found this piece of code
I have a similar problem – Anyone know how to show the page number on the index page when you go prev next pages?
When I need it for my new template, I found your post by googling with keyword ‘ only on homepage “wordpress” ‘
That’s cool. It’s working at all. Thank you.
Gio,
Can you give me a little more specific information on exactly what happened and perhaps I can help you troubleshoot it?
John
Femikey,
When you are in the admin control panel and select “Presentation”, you should see a tab that says “Theme Editor”. It is when you are within the theme editor that you can make the changes that I previously listed.
In the theme editor find the index.php page and add the code whereever you want the ads to appear. You may have to experiment a bit to get it in just the spot you want it, so create a backup of the original code before you get to messing with things just to ensure you can revert back if necessary.
John
hi i want to ask something about how to put ads at wordpress homepage only? because i have a wordpress blog but when i check the presentation i dont have index.php i only have themes, widgets, extras, custom image header and css stylesheet editor. How could i add the url that only shows to my homepage if i use the css stylesheet editor? I want to know this because there’s a company offer me to add their link on my link that shows only to my wordpress homepage and not with the other links for my post. Can you help me please? thanks..
femikey
WOW! Easy and effective! Thanks lot man ^_^
P/S: Why do u have TWO *subscribe-to-comment* (top and below)? Izzit redundant? No offend, just askin if u might not have seen it… thx again for the wonderful tip :)
Sorry Madel, it looks like you are using WordPress.com and I’m not sure how, or if, you can edit the themes there. This tip was really for the stand-alone WordPress that can be downloaded from WordPress.org.
John
Glad that helped you out Heris! :-)
Many many thanks for the tip. I have been looking for the answer on how to do it with Tigopedia Reloaded WP theme (it doesn’t separate page for homepage and category/archive), and your tip works very well.
To bad I don’t use adsense on most of my blogs :))
Hi, I am wondering how can I go to the index.php to my theme, I realli want to put ads on my blog but can’t do it yet..help pls..
Thanks for the code–I will certainly implement it on my blogs.
Does anybody know of similar code that can be used for any/all php scripts, not just wordpress?
Nice one. Will definitely plug it in my blog. Thx :-)
Thank you a lot for this hint, I will start using it after I add this comment :)
Storm,
Thanks for the tip it worked perfectly! I’ve updated the article to reflect the change. I really appreciate it.
John
I was looking for just that, and found it here:
http://www.douglaskarr.com/2006/09/06/wordpress-hack-after-the-first-post-only-on-the-home-page/