Posted on Jul 09, 2007 - 1:20am by John P. in Tutorials, Wordpress
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”.
I use the "No Adverts for Friends" plugin by Donncha O Caoimh
[...] He’s devised a way to do this (front-page only ads) and he’s kind enough to share the text link ads work-around with the rest of us. If you are one of those bloggers who are earning money with text link ads, you owe it to yourself to take a look at the code and see if it’s something you want to implement on your own site. Of course, if you aren’t a current text link ads publisher, I do hope you’ll sign up using my link. [...]
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/
Storm,
Thanks for the tip it worked perfectly! I’ve updated the article to reflect the change. I really appreciate it.
John
Thank you a lot for this hint, I will start using it after I add this comment
Nice one. Will definitely plug it in my blog. Thx
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?
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..
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
To bad I don’t use adsense on most of my blogs
)
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.
Glad that helped you out Heris!
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
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
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
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.
I have a similar problem – Anyone know how to show the page number on the index page when you go prev next pages?
Happy that I found this piece of code
Thanks for the code.
Happy I can find your post on it.
Really helpful.
[...] ProCut 1 is super piece. I enjoyed how to place a login form in the sidebar. Take a look at Tutorial: How To Put Ads on WordPress Home Page Only. I read Tutorial: Add 3 Centered Columns to Wordpress [...]
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..
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.
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!
[...] Via Onemansblog.com [...]
Thanks mate. It will help me to monetize my site well.
It works like a charm, thanks for your tutorial.
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