How to Code a WordPress Footer Link to Show for Homepage Only

It’s important that web designers be able to credit themselves by adding a footer link to a website in the footer, but with the recent Google algorithm changes, having your link on every page of the site is actually a negative ranking factor with regard to SEO. You’re much better off with an internal page with a blurb and a link within the content or with a single link on the homepage in the footer.

code-wordpress-footer-link

For most clients, and in most situations, adding the footer credit link is much easier, and clients will seldom mind its addition there, especially if it’s only located on a single page of their site.

Change Your Footer Link to Show Only on the Homepage

In your footer.php file within the active WordPress theme you’ll want to add this bit of code where you’d like the link to appear:

<?php if (is_front_page()) { ?>
<a href="http://www.websitewhatever.com">Anchor Text Here</a>
<?php } ?>

The code above should work for any given theme. It’s better than this code, which may not work on some advanced themes, but does generally work fine:

<?php if (is_home()) { ?>
<a href="http://www.websitewhatever.com">Anchor Text Here</a>
<?php } ?>

Now, as a side note, you can add non-link text within the code as well such as:

<?php if (is_front_page()) { ?>
Some other non anchor footer text <a href="http://www.websitewhatever.com">Anchor Text Here</a>
<?php } ?>

For some themes, the footer.php file may not actually be where you need to add this code. Most themes have something in the footer, however, such as a copyright. You can use Textwrangler or Notepad++ to do a multifile search and look for the copyright code. Then you will have found the correct footer file.

We’ve changed the footer.php files on all of our client sites to only show on the homepage and our link profiles look much more natural. We highly advise using the above code to make your WordPress footer credit link appear only on the homepage.

15 replies
  1. Michael
    Michael says:

    I like the following variant: pick an interior page, perhaps one that has context relevant to the link and then make the link show up only on that interior page. It’s based on this : is_page(42); where 42 is the ID of the page where you want the link to show up

    Reply
    • Ryan Howard
      Ryan Howard says:

      You can also drop the code in a widget area by making use of one of the php text widget plugins available.

      Reply
  2. zituz
    zituz says:

    Awesome, man.
    I use the first code : front_page and it’s work in several premium theme for my client site. Many thanks for this 🙂

    Reply
  3. Thomas Jones
    Thomas Jones says:

    Hi Ryan,

    How would you go about this in a wp plugin? lets say i have a 3 img alt tags.

    brand name
    web design
    thomas jones

    obviously i dont want them to keep changing dynamically just pick one and stick to it after installation of the plugin.

    how would you go about this?

    Reply
  4. Geoff
    Geoff says:

    Could you please advise where to place it in twenty eleven theme relative to the existing do_action?

    Also, what if I want other pages to show the credit but not the link – what code do I add for non-home pages?

    This is the 2011 code at present:

    <a href="” title=””>

    thanks

    Reply
  5. Anand Rao
    Anand Rao says:

    Hi
    I spent hours trying to make it work. Then I stripped out
    “!– ” and “–” in your code and it worked!
    Wonder why these were put in?

    Reply
    • Ryan Howard
      Ryan Howard says:

      Good catch, and sorry about that. We changed to a new plugin to allow us to add code blocks to our posts, and it must have added those commented out lines automatically. Should be good to go now.

      Reply
  6. Dale
    Dale says:

    The Widget is the best implementation, because if you alter the theme code or wordpress code directly, it will be overwritten on updates.

    Reply
    • Ryan Howard
      Ryan Howard says:

      You can avoid overwriting modifications you make to your active theme by using a child theme. Much more flexible, easy to set up, and will revolutionize your efficiency in updating the WordPress core and your theme.

      Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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