Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sabrina-zeidan/ba03065f7b036093728b2d25823e16e2 to your computer and use it in GitHub Desktop.
Save sabrina-zeidan/ba03065f7b036093728b2d25823e16e2 to your computer and use it in GitHub Desktop.
Filters images links from post content on page load with the_content filter [Wordpress]
add_filter( 'the_content', 'attachment_image_link_remove_filter' );
function attachment_image_link_remove_filter( $content ) {
$content =
preg_replace(
array('{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}',
'{ wp-image-[0-9]*" /></a>}'),
array('<img','" />'),
$content
);
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment