Created
November 8, 2012 10:37
-
-
Save FutureMedia/4038031 to your computer and use it in GitHub Desktop.
Wordpress function to remove images from posts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want remove all images from a Wordpress post. Read the code comments for alternative uses.