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
.
Related Posts:
- Change the output for [gallery] shortcode
- How to add php to theme to show alt attributes
- How to Display an Image Uploaded through a Meta Box in a Template?
- Featured Images on Front Page
- Display different header images based on current page
- Why is wordpress searching for @2x images?
- Custom page template to display all image attachments
- Is There A Way Of Using the_post_thumbnail() to Pull In A Specific Image From The Media Library
- How to create ‘Local’ filters for WordPress srcset sizes in template parts?
- how to move from content and place them elsewhere on a page template?
- HowTo: develop WP template with dynamic background image
- Apply nextgen-gallery lightbox effect [closed]
- How to Featured content with images in home page?
- How to create a title images for different posts?
- How to get rid of undefined variable in previous post image
- How to add php to theme to show alt attributes
- second featured post not displaying on page [closed]
- Display images in template file
- Show uploaded images in full size
- show hide image script after 4 seconds [closed]
- Create custom page templates with plugins?
- Restricting users to view only media library items they have uploaded?
- How do I disable responsive images in WP 4.4?
- Filter to remove image dimension attributes?
- How to get a list of all the possible thumbnail sizes set within a theme
- How do I get the avatar URL instead of an HTML IMG tag when using get_avatar?
- Custom templates not showing up in template dropdown
- Image Upload from URL
- Programmatically adding images to media library
- How do I delete all UNUSED images from my uploads directory?
- Set default image sizes in WordPress to hard crop
- Is it possible set a featured image with external image URL
- get attachment title based on attachment id
- Stop wordpress from hardcoding img width and height attributes
- Handle issues with change of image scaling (rounding) in 4.1 (WP Ticket #18532)
- Programmatically get images by URL and save in uploads folder
- Prevent WordPress from generating medium_large 768px size of image uploads?
- remove or update add_image_size
- Get Image Description
- How to extend the gallery block in Gutenberg?
- Image quality based on image size
- Function to get URL of original uploaded image – full size
- how to get original image using wp_get_attachment_image_src
- What is a good alternative to using $content_width for image optimization?
- get the attachement url for the medium sized image
- Can I attach image to post without adding it to post?
- Automatically replace original uploaded image with large image size
- WordPress crop tool greyed out
- How to scale up featured post thumbnail?
- Upload images to remote server
- Custom image size / thumbnail – Crop to aspect ratio even when source image is smaller than set dimensions
- Each custom image size in custom upload directory?
- Getting Images from theme’s directory in pages
- Set default image link target in Gutenberg image block
- Add an alignment option for images
- How can I load a page template from a plugin?
- How to delete resized (cropped) image uploads and prevent future resizing?
- How to automatically add rounded corners to thumbnails?
- WordPress adding scaled images that don’t exist (1536×1536 and 2048×2048)
- Download an image from a webpage to the default uploads folder
- Add image size where largest possible proportional size is generated
- Is there a WordPress plugin that registers a plugin file as a custom page template?
- WP 4.4. responsive images browser choosing the “wrong” one
- After Moving a Site to Another Domain, All Images Are Lost
- Prevent WordPress from adding image’ title automatically
- Overide Gallery Default Link to Settings
- Retrieve featured image
- Page editor missing Templates drop down
- How to change image type for specific size?
- Add new image size to media uploader so users can insert into post?
- Is it possible to stop selected plugins from loading on certain template pages?
- Passing parameters to a custom page template using clean urls
- How to insert pictures without hard coded dimensions?
- Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
- How to modify image editor dialog options on WordPress?
- Why WordPress automatic cropping all my images?
- Allow contributor role to upload images and not edit already published articles
- What’s the proper way to find and remove duplicate images from posts and the media library?
- Remove images (files) that were generated when using add_image_size()
- get_post_gallery with Gutenberg
- Is there a hook which fires after all thumbnails are generated?
- Auto Add Image Title,Caption,Alt Text,Description while uploading Images in WordPress
- Is there a simple way to just insert a link to an image (without inserting an image)?
- Watermarking Images with WordPress with WP_Image_Editor
- How to avoid WordPress stripping EXIF metadata when resizing images?
- is it possible to replace the use of gd_lib with imagick or ImageMagick?
- How to edit contents of dynamic_sidebar()?
- How to have different captions for same image, for galleries?
- Get attachment/image info in JS
- How to reference a theme image in a stylesheet?
- wp_get_attachment_image_src and server path
- Limit image resolution on upload
- How to move page templates to custom folder?
- How to display a page’s featured image?
- Separate Media Library for each user
- Setting a custom sub-path for blog without using pages?
- Featured image shortcode
- Ways to have multiple front-page.php templates that can be swapped out?
- get_post_gallery_images returns thumbs . I want full size
- Setting JPEG compression for custom image sizes doesn’t work in specific cases