Contact Form 7 auto added p tags

前端 未结 5 869
南旧
南旧 2021-01-31 08:54

I have next code inside contact form 7 editor

5条回答
  •  感动是毒
    2021-01-31 09:48

    Add this in your functions.php file

    function reformat_auto_p_tags($content) {
        $new_content = '';
        $pattern_full = '{(\[raw\].*?\[/raw\])}is';
        $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
        $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
        foreach ($pieces as $piece) {
            if (preg_match($pattern_contents, $piece, $matches)) {
                $new_content .= $matches[1];
            } else {
                $new_content .= wptexturize(wpautop($piece));
            }
        }
    
        return $new_content;
    }
    
    remove_filter('the_content', 'wpautop');
    remove_filter('the_content', 'wptexturize');
    
    add_filter('the_content', 'reformat_auto_p_tags', 99);
    add_filter('widget_text', 'reformat_auto_p_tags', 99);
    

    Then on your post editor wrap your contact form 7 shortcode with raw shortcode

    e.g.

    [raw][contact-form-7 id="1" title="Contact Us"][/raw]
    

提交回复
热议问题