$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>templates - I want to rel=nofollow wordpress images|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

templates - I want to rel=nofollow wordpress images

matteradmin11PV0评论

I have a default theme. When i add media to wordpress site. By default it use simple "a href" tag I want to add attribute "rel=nofollow" to it. Can anybody please point me in right direction?.

I have a default theme. When i add media to wordpress site. By default it use simple "a href" tag I want to add attribute "rel=nofollow" to it. Can anybody please point me in right direction?.

Share Improve this question edited Nov 8, 2014 at 14:07 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Nov 8, 2014 at 13:06 HybridHybrid 1033 bronze badges 2
  • You have tagged this question with both wordpress and wordpress - is this a question about a self-hosted WP (and hence on-topic) or about a blog on wordpress (and hence not)? – Johannes P. Commented Nov 8, 2014 at 13:26
  • Not a blog. Self hosted – Hybrid Commented Nov 8, 2014 at 13:27
Add a comment  | 

2 Answers 2

Reset to default 1

You need to hook into the image_send_to_editor filter. This allows you to modify the markup used when inserting an image into the content editor.

Something like this should work:

add_filter('image_send_to_editor', 'my_add_rel_nofollow', 10, 8);
function my_add_rel_nofollow($html, $id, $caption, $title, $align, $url, $size, $alt = '' ){

    // check if there is already a rel value
    if ( preg_match('/<a.*? rel=".*?">/', $html) ) {
        $html = preg_replace('/(<a.*? rel=".*?)(".*?>)/', '$1 ' . 'nofollow' . '$2', $html);
    } else {
        $html = preg_replace('/(<a.*?)>/', '$1 rel="' . 'nofollow' . '" >', $html);
    }
    return $html;
}

This will first check if there is already a rel attribute, and add the no_follow. Or, if there is no rel attribute, it will add one, and set it to nofollow.

This works for me. Not sure if its always been there pf if its part a nofollow plugin?

Post a comment

comment list (0)

  1. No comments so far