0

WordPress の各投稿の後にいくつかのコードを挿入したいのですが、この後、たとえば single.php でそれを実行できることはわかっています。

<?php the_content(); ?>

ただし、それを行うと、間違った場所に配置されます..投稿の例は次のとおりです。 this-christmas/ -- 上記のコード例の後に配置すると、社交的な & facebook リンクの後に配置されます.....それらの前に配置したいので、投稿の直後です。

私はいくつかのチェックとテストを行いました..このコードはpost-template.phpからここにあります

function the_content($more_link_text = null, $stripteaser = 0) {
    $content = get_the_content($more_link_text, $stripteaser);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    echo $content;
}

facebook と社交的なコードが apply_filters() 関数内の出力に挿入されているようですが、どこにあるのかわかりません。

私がやろうとしていることについて何か助けはありますか?

4

1 に答える 1

1

コンテンツと関数に対するフィルターの例を次に示します。

    function the_content_replacer($content) 
    {
//global $post, $posts;
       //$content = str_replace(']]>', ']]&gt;', $content);

 $content .= "\n<div style=\"display:none;\">text here</div>"; 

//$content = preg_replace('/="http:\/\/cnn/i', 
// '="http://example.com?http://cnn', $content, -1); 
       return $content;
    }
    add_filter('the_content', 'the_content_replacer', 1);
  1. http://wordpress.stackexchange.comのこのフィルターのより多くの例........
  2. テーマの「functions.php」ファイルのコンテンツをコピーして貼り付けるだけで機能します。
  3. マルチサイトを実行している場合は、ディレクトリ wp-content/mu-plugins にドロップするだけで、マルチサイト環境のすべてのブログで機能します。
  4. 3 番目のパラメーターは、フィルターを適用するときの重要性を決定します。https ://wordpress.stackexchange.com/questions/2126/at-what-priority-does-add-filter-overwrite-core-functions を参照してください。

--> WordPress に関する質問はすべてhttp://wordpress.stackexchange.comに投稿することをお勧めします!!!

--> たとえば使用する場合

$content .= "\n<div style=\"display:none;\">text here</div>";

段落の終了タグは削除されません (文字列の先頭にある改行に注意してください)。

于 2010-11-26T20:48:03.853 に答える