Wordpress Gallery Shortcode Pregreplace -
basically need remove gallery shortcode wordpress content, i'm using
echo preg_replace('/\[gallery ids=[^\]]+\]/', '', get_the_content() );
it removing gallery shortcode successfully, paragraph tags need keep. idea want output in content except gallery.
you use wordpress strip_shortcode function.
look @ example in codex. can create filter strips shortcodes:
function remove_shortcode_from($content) { $content = strip_shortcodes( $content ); return $content; }
and call when need (in template):
add_filter('the_content', 'remove_shortcode_from'); the_content(); remove_filter('the_content', 'remove_shortcode_from')
edit 1
another way (and answering comment) can use wordpress apply_filters function in content after remove undesirables shortcodes.
//within loop $content = get_the_content(); $content = preg_replace('/\[gallery ids=[^\]]+\]/', '', $content ); $content = apply_filters('the_content', $content ); echo $content;
but not recommend that. think forcing site modify content of post make hard understanding. maybe should work wordpress excerpt , avoid problem.
Comments
Post a Comment