• Resolved MrTrafic

    (@mrtrafic)


    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!

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    Thread Starter MrTrafic

    (@mrtrafic)

    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>

    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.

    Thread Starter MrTrafic

    (@mrtrafic)

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

    Maybe something wrong with the else bit…

    Thread Starter MrTrafic

    (@mrtrafic)

    Back again…
    No solution found yet… anyone help?

    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?

    Thread Starter MrTrafic

    (@mrtrafic)

    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 😉

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Nofollow and conditionnal’ is closed to new replies.