Remove auto added

from a page that has no literal content (uses shortcodes)

后端 未结 5 676
我在风中等你
我在风中等你 2021-01-05 07:16

I have a WordPress powered website that on the homepage uses a static page with nothing but shortcodes to generate the content.

The page gets these shortcodes by set

相关标签:
5条回答
  • 2021-01-05 07:23

    There are a few things you can try.

    You can pospone the wp_autop because it processes before the shortcode output:

    remove_filter( 'the_content', 'wpautop' );
    add_filter( 'the_content', 'wpautop' , 12);
    

    Or use the cleanup_shortcode_fix() function that should help with your issue:

    function cleanup_shortcode_fix($content) {
        $array = array('<p>[' => '[', ']</p>' => ']', ']<br />' => ']', ']<br>' => ']');
        $content = strtr($content, $array);
        return $content;
    }
    
    add_filter('the_content', 'cleanup_shortcode_fix');
    $string = preg_replace_('/<p>s*</p>/', '', $string);
    add_filter('the_content', 'cleanup_shortcode_fix', 1);
    
    0 讨论(0)
  • 2021-01-05 07:25

    Since you want to only remove <p> tags on the home page, add the code below to your functions.php file:

    add_action('pre_get_posts', 'remove_autop_from_home');
    function remove_autop_from_home() {
        // check to see if we are on the home page
        if(is_home()) {
            remove_filter('the_content', 'wpautop');
        }
    }
    
    0 讨论(0)
  • 2021-01-05 07:26

    Try this(paste this code somewhere in functions.php):

    function shortcode_empty_paragraph_fix($content){   
        $array = array (
            '<p>[' => '[', 
            ']</p>' => ']', 
            ']<br />' => ']'
        );
    
        $content = strtr($content, $array);
        return $content;
    }
    
    add_filter('the_content', 'shortcode_empty_paragraph_fix');
    
    0 讨论(0)
  • 2021-01-05 07:32
    jQuery('p:empty').remove();
    

    Also you can use JS. Above code will help you to remove all empty p tag from the page

    0 讨论(0)
  • 2021-01-05 07:42

    There are various functions aside from wpautop() that filter post content, such as force_balance_tags(), which was designed to balance bad HTML coming in via the editor.

    They're mostly defined in formatting.php, where you can see the various code in source.

    Removal of these filters can be as simple as one line, as you point out:

    remove_filter('the_content', 'wpautop');

    For more information: http://codex.wordpress.org/Function_Reference/wpautop

    Check out below links which will help you.

    1. Removing <p> and <br/> tags in WordPress posts
    2. wordpress-wrapping-shortcodes-with-p-tags
    3. Disable wpautop Plugin

    may this help you.

    0 讨论(0)
提交回复
热议问题