Skip to content

Instantly share code, notes, and snippets.

@FutureMedia
Created November 8, 2012 10:37
Show Gist options
  • Save FutureMedia/4038031 to your computer and use it in GitHub Desktop.
Save FutureMedia/4038031 to your computer and use it in GitHub Desktop.
Wordpress function to remove images from posts
<?php
/**
* Remove images from post content
*
* credits: http://bavotasan.com/2011/a-better-way-to-remove-images-from-a-wordpress-post/
*
* This will remove images on ALL posts! If you don't want this,
* use it in the template code and then add
* remove_filter( 'the_content', 'og2013_no_images' );
* you can also use <?php echo preg_replace("/\]*[.]*\>/i”,”",get_the_content(),1); ?>
*
* @since og2013 1.0
*/
if ( !function_exists( 'og2013_no_images' ) ) {
function og2013_no_images( $content ) {
$postOutput = preg_replace('/<img[^>]+./','', $content);
return $postOutput;
}
}
add_filter( 'the_content', 'og2013_no_images', 100 );
@FutureMedia
Copy link
Author

If you want remove all images from a Wordpress post. Read the code comments for alternative uses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment