web-dev-qa-db-ja.com

Contact Form 7自動追加pタグ

Contact Form 7エディター内に次のコードがあります

<div class="row">
    <div class="col-sm-8 col-sm-offset-2">
        <div class="row">
            <div class="col-sm-4">
                [text* name class:border-field placeholder "Name"]
            </div><!-- End of col -->
            <div class="col-sm-4">
                [email* email class:border-field placeholder "Email"]
            </div><!-- End of col -->
            <div class="col-sm-4">
                [text subject class:border-field placeholder "Subject"]
            </div><!-- End of col -->
        </div><!-- ENd of row -->
    </div><!-- End of col -->
</div><!-- ENd of row -->

<div class="row">
    <div class="col-sm-8 col-sm-offset-2">
        [textarea message class:border-field placeholder "Message"]
    </div>
</div><!-- End of row -->

<div class="row text-center">
    <div clas s="col-sm-12">    
        [submit class:btn class:btn-black-fill class:btn-small "Submit"]  
    </div><!-- End of col -->
</div><!-- End of row -->

問題は、各要素のほぼ後にランダムなpタグを追加することです。また、最初のテキストフィールドは、何らかの理由で、他の2つのフィールドがすべてインラインである必要があるときに少し上にあります。以前はプレーンHTMLでコード化されていて、すべてのフィールドがインラインであったため、これはcssの問題ではないと思います。

24
Nenad Vracar

Contact Form 7 Docs によると、次の定数をwp-config.phpに配置することにより、プラグインの「wpautop」を無効にできます。

define( 'WPCF7_AUTOP', false );
56
rnevius

_wp-config.php_を編集しても解決できない場合は、便利なフィルターがあります。 _functions.php_に入れてください。

add_filter('wpcf7_autop_or_not', '__return_false');

39
skip405

Functions.phpファイルにこれを追加します

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);

次に、投稿エディタで、コンタクトフォーム7ショートコードをrawショートコードでラップします

例えば.

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

私はこれについて何か言いたいのですが、自動Pタグのフォームを減らしたい場合は、以下のフィルターを使用して、function.phpにブローコードを書くだけです。

add_filter('wpcf7_autop_or_not', '__return_false'); 
2

私は多くの答えを試しましたが、何も機能しませんでしただから...
空のPタグを明確にターゲットにするために単純なCSSを使用することになりました
次のようなフォーム自体:

.wpcf7-form p:empty { display: none; }

これは私にとってはうまくいき、簡単な解決策でした。

0
Sagive SEO