0

I have been trying but its not working.

but if i try

<?php echo do_shortcode("[mimo]"); ?> <?php echo do_shortcode("[mibaby]"); ?>

it will work fine.

But to apply it in post content using [mimo] [mibaby]

it won't work.

Here is the Functions i am using...

function wpb_custom_new_menuw() {
  remove_filter( 'the_content', 'wpautop' );
}
add_shortcode('mibaby', 'wpb_custom_new_menuw');



function wpb_custom_new_menu() {
  remove_filter( 'the_excerpt', 'wpautop' );
}
add_shortcode('mimo', 'wpb_custom_new_menu');
  • It is weird to use shortcodes to remove filters. What are you trying to do exactly? – cybmeta Sep 26 '17 at 6:49
0

I believe what happens is that is that by the time the shortcodes are parsed, it has already called the the_content filter. Afterall, the shortcode is inside the content.

Try using the single_template and page_template hooks instead.

0

It is simple - you cannot remove filters that are fired on the content from inside content after mentioned filters are fired. Schematially you are trying to do something like this (there are no exact names for simplicity):

|- wp_core_fires_its_functions_and_plugins
|-- wp_core_gets_raw_content
|--- wp_core_runs_filters_on_fetched_content (execution of shortcodes is done here)
|---- [mimo] - is fired inside filtered content and tries to remove filters which are already applied

All this is a wrong way to implement filter remove.

I would suggest to remove such filters in other way - make a settings page with field to apply an array of post IDs and check if a post/page id is inside that array inside its template file with something like this:

$fetched_posts_array=explode(',', get_option('posts_array_to_unfilter'), ''); //get_option gets some string like '99,566,435,2345'
if(in_array($post->ID, $fetched_posts_array){
  apply_filter('the_content', $post->post_content);
} else {
  echo $post->post_content;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.