WordPress: Add Homepage-only links

Well, this is my first guest post at DG…let’s start out with something useful in WordPress…

Sometime ago, I had to add a “homepage-only” link on my WP Blog, that would appear only on the Homepage of the blog and no where else. There isn’t any such option in WP so I tried out some googling to get a solution for it :)

After a lil bit googling, I found a PHP script for WP to display links on the homepage only…Here it is:

<?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>
<?php } ?>

And know what! Not just links, but you can also put other content over there which you want to appear only on the homepage (like some photos or widgets)…

Getting this script to work is really easy. Just add the link code over there in the place of “homepage-only content here”. Then use the “Theme Editor” to put it there in the theme files, wherever you want it to be :)

Note: This script won’t work if added to the “Widgets”, as PHP codes aren’t executed in the “Widgets” by WP.

Here’s a way for making this script work in the “Widgets” without editing the theme template files…

  1. Install the Exec-PHP plugin.
  2. Enable and Configure it.
  3. Now just directly add the PHP script to the “Widgets” :D
Administrator’s note:
This article was posted by our guest author Hack-minded . Hack-minded is a computer geek and u can find his blog at : www.hackerslane.com.

is_home() is a WP function that returns true if the current page is the blog’s home page. Similarly useful functions are is_paged() , is_search() , is_404() etc…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

2020 All rights reserved | Powered by WordPress
Back to top
Theme by dynamicguru.com