Home » How to Guide

How to show ads only on Homepage in wordpress

Written by Amit Bhawani on Monday, 14 April 2008No Comment
ADVERTISEMENTS

Ravi asked me the following question :

I have a wordpress based blog and i want to display adverts only on the homepage of my blog and not on the sitewide, because i want to have a control on homepage and sitewide adverts. Is this possible?

This is very much possible because wordpress files can be customised to the maximum since its one of the best CMS made ever and anyone can play around with it and develop great blogs. Now lets get back to the point regarding showing some type of advert or code only on the homepage and not sitewide by limited its display.

<?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>
You need to add your advert code here which is shown on the homepage only.
<?php } ?>

Another option would be trying with a php code which runs a statement where in if its homepage then certain code is run if not its void.

if (is_home())
{
echo ‘is_home() returned true’;
}
else
{
echo ‘is_home() returned false’;
}

and if you are looking for the easiest way then try out this following code :
<?php if ( is_home() ) { ?>
Here the content only on the index page
<?php } ?>

This is all a part of Conditional Tags feature of wordpress which has lot more options and the ones i have posted above are the easiest of all. Hope this helps you out in adding/showing some stuff only on the index/homepage of your blog and limit them from displaying on the sitewide section.

We will send you some more information related to How to show ads only on Homepage in wordpress

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.