remove empty

tags from wordpress shortcodes via a php functon

前端 未结 7 1823
余生分开走
余生分开走 2021-02-13 10:20

Looking for a php function (non-jQuery or wpautop modification) approach to remove

from within wordpress.

I tried this but it does not w

7条回答
  •  迷失自我
    2021-02-13 10:58

    What you need is a mix of jquery and php... that is the only working way
    that i found to be working really well. i have tutorial on my site but
    in order to keep stuff inhouse here goes

    The jQuery:
    include this in some JS file you already enqueue

    jQuery(function($){
        $('div#removep > p').filter(function() {
            return $.trim($(this).text()) === '' && $(this).children().length == 0
        })
        .remove()
    })
    

    A shortcode you can later use:
    in your functions.php or included file

    function sght_removep( $atts, $content = null ) {return '
    '.do_shortcode($content).'
    ';} add_shortcode('removep', 'sght_removep');

    Now you can wrap specific stuff like this:

    [removep]
    Some text i write directly in wordpress wysiwyg
    

    <-- this would get removed [/removep]

    This solution requires some know how but it works!
    Hope this helps...

提交回复
热议问题