WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Nofollow and conditionnal (8 posts)

  1. MrTrafic
    Member
    Posted 3 years ago #

    Hello Everyone,

    I working on netlinking and would like to apply nofollow on some of my external links.
    I'm tryong to have link with rel="dofollow" on home page and rel"nofollow" on all others.
    This the code I came with but doesn't work for the moment:

    <a title="123" rel="<?php if (is_home()) {echo ('dofollow');} elseif (is_single()) {echo ('nofollow');}?>" href="http://mywebsite.com">My link</a>

    Any kind of help would be more than welcome ;-)
    Cheers!

  2. deeem119
    Member
    Posted 3 years ago #

    Which way does it not work? Are all rel attributes being set to dofollow, nofollow or blank?

    You might want to get rid of the second condition (is_single()) and just rely on the first.

  3. MrTrafic
    Member
    Posted 3 years ago #

    Hey Deem119,

    Thanks for your reply!

    All posts are set on dofollow with code above.

    If I rely only on first one, all pages have the "nofollow" attribute
    (code below)
    <a title="123" rel="<?php if (is_home()) {echo ('dofollow');} else {echo ('nofollow');}?>" href="http://mywebsite.com">My link</a>

  4. deeem119
    Member
    Posted 3 years ago #

    Try using is_front_page() instead of is_home() - I think that might be the effect you're looking for.

    <a title="123" rel="<?php if (is_front_page()) {echo ('dofollow');} else {echo ('nofollow');}?>" href="http://mywebsite.com">My link</a>

    is_home only triggers on the main posts page.

  5. MrTrafic
    Member
    Posted 3 years ago #

    I still have "dofollow" attribute on all other pages :-S

    Maybe something wrong with the else bit...

  6. MrTrafic
    Member
    Posted 3 years ago #

    Back again...
    No solution found yet... anyone help?

  7. deeem119
    Member
    Posted 3 years ago #

    I did have a bit of a play with it. Not sure how you've got yours set up. I've tried a very basic test install, just WP 3.0.3 with a couple of pages and some posts with the default theme. I put that code block at the top, and it worked how I think you wanted it, i.e. the homepage, http://www.domain.com/, shows the dofollow link and all other pages, including posts, show nofollow.

    Any chance we can have a peek at the site?

  8. MrTrafic
    Member
    Posted 3 years ago #

    Wow! Thanks for testing ;-)

    I finally put the site online. Up to know I was running it on my computer with wampserver.

    It's working properly once online, but not on my computer... weird...

    Thanks for your help anyway !

    For info, the site is http://parcs-d-attraction.com the links are at the bottom of the page and working ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic