在WordPress中的每个帖子之后插入代码

问题描述:

我想在WordPress的每篇文章之后插入一些代码...我知道您可以在此之后例如在single.php中完成

I am wanting to insert some code after each post in WordPress... I know you can do it after this for example, in single.php

<?php the_content(); ?>

但是,如果我这样做,它将放在错误的位置..示例示例在这里:

However if I do that it puts it in the wrong place.. an example post is here: http://www.hardwareblog.com/348/computer-hardware/top-10-gadget-gift-ideas-to-avoid-this-christmas/ -- if I put it AFTER the code example above it will be placed AFTER the sociable & facebook links..... I want to put it BEFORE those, so it's RIGHT AFTER the post.

我做了一些检查&测试..此代码来自post-template.php

I did some checking & testing.. this code here from 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()函数中的输出中.尽管我无法确定在哪里.

It seems the facebook & sociable code is inserted into the output within the apply_filters() function.... though I can't work out where.

我在做什么方面有帮助吗?

Any help on what I am trying to do?

以下是内容和功能过滤器的示例:

Here is an example of a filter on the content and the function:

    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. 第三个参数确定了应用过滤器的重要性,请参阅:
  1. much more examples on this filter on http://wordpress.stackexchange.com ..........
  2. You can just copy and paste the piece of content in the file "functions.php" in your theme and it will work.
  3. You can also just drop it in the directory wp-content/mu-plugins if your run multisite so it works on all the blogs in your multisite environment.
  4. the third parameters determines the importance of when applying the filter, see: https://wordpress.stackexchange.com/questions/2126/at-what-priority-does-add-filter-overwrite-core-functions

->最好将所有WordPress问题发布在 http://wordpress.stackexchange.com !!!

--> it is better to post all WordPress questions in http://wordpress.stackexchange.com !!!

->如果您使用例如

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

它不会删除结尾的段落标记(请注意字符串开头的换行符)

it will not remove a closing paragraph tag (note the linebreak at the beginning of the string)