WordPress.org

Ready to get started?Download WordPress

Forums

"nofollow" in posts (13 posts)

  1. Broomy
    Member
    Posted 7 years ago #

    I've seen a plugin that adds the nofollow tag to links left in comments, but is there a way I can also do this for the actual post. I plan on having quite a few authors but don't want spammers signing up and benefiting from links to their site.

  2. kubicka
    Member
    Posted 7 years ago #

    If you don't mind monkeying with code, you can do this:

    Open template-functions-post.php in the wp-includes folder and find this:

    function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    echo $content;
    }

    then add this line just before the last line of the function:

    $content = str_replace('<a href', '<a rel="nofollow" href', $content);

    so the function now looks like this:

    function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    $content = str_replace('<a href', '<a rel="nofollow" href', $content);
    echo $content;
    }

    Seems to work just fine.

  3. xinfo
    Member
    Posted 7 years ago #

    sorry to hi-jack i like to know i found some where that wordpress have default no follow tag its that true ?

  4. Kafkaesqui

    Posted 7 years ago #

    "i like to know i found some where that wordpress have default no follow tag its that true ?"

    Yes. Commenter urls and any urls within comments are automatically given the rel=nofollow attribute.

  5. Kafkaesqui

    Posted 7 years ago #

    By the way, here's kubicka's idea rolled into plugin form (what can I say, I like to avoid editing the core code):

    Nofollow in Posts plugin:
    Download plugin | View source

    Only real diff with kubicka's suggestion is I swapped out str_replace for preg_replace to perform a bit of pattern matching (in those potential cases where an author might have inserted attributes et al between <a and href).

  6. xinfo
    Member
    Posted 7 years ago #

    Kafkaesqui thank you very much looking for long time for this plugin i already open new topic long back

    one more question regarding your plugin its possible to apply
    rel=nofollow attribute only to out going (other website or blog) blog link not to own blog link

  7. You know, this is a heck of a lot easier, Kafkaesqui:

    add_filter('the_content', 'wp_rel_nofollow', 15);

    :)

  8. Kafkaesqui

    Posted 7 years ago #

    It is when you know the fricken function, now isn't it V? But hey, can you solve xinfo's last request with a one line filter plugin? ;)

    xinfo, I'll look at modifying the plugin to do that...

    EDIT: OK xinfo, R1.0.1 (same links above) should filter out links back to the blog.

  9. xinfo
    Member
    Posted 7 years ago #

    You guys Amazing

    Thank you Kafkaesqui for considering my Request

    This plugin will help all the blog who aware of rel=nofollow
    attribute Thank you Once again

  10. clublakers
    Member
    Posted 7 years ago #

    Great plugin!

    For directing spiders I create site and category maps with Pages. These Pages are automated menus of all Posts on the website.

    The nofollow plugin is applying itself to both Posts and Pages. Is it possible to only add the nofollow command to Posts, but not Pages?

    Thanks!

  11. Kafkaesqui

    Posted 7 years ago #

    clublakers, you'll have to modify the plugin's source for this. Just locate the line that begins:

    $text = preg_replace(

    just above it, you can stick this line into the nofollow_in_posts() function:

    if( !is_page() )

    That will tell the plugin to perform the text 'replace' that inserts the nofollow only when one is *not* on a Page.

  12. clublakers
    Member
    Posted 7 years ago #

    Got it, thanks again for your help Kafkaqsqui.

  13. fitztrev
    Member
    Posted 7 years ago #

    I'm using this and it works great. Is there a way to create an array of sites that can bypass the nofollow rules? Like a whitelist?

    I've tried coding it in myself but no luck.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags