Jul 7, 2011

How to Remove Images from a WordPress Post

This is a simple way to remove images from wordpress post. just add this piece of code.
[php]<?php
function remove_images( $content ) {
$postOutput = preg_replace('/<img[^>]+./','', $content);
return $postOutput;
}
add_filter( 'the_content', 'remove_images', 100 );
?>[/php]
If you include this in your functions.php it will remove every image from the content everywhere the_content() function has been used. That isn’t probably what you want, but what you can do is include this function in a specific page template, such as your index.php file, and then at the end of that file include the following to remove the filter:

[php]
<?php remove_filter( 'the_content', 'remove_images' ); ?>

[/php]

No comments :

Post a Comment