他们通过过滤器、动作和挂钩来实现它。
在您的情况下-使用the_content
过滤器..
示例(来自法典):
add_filter( 'the_content', 'my_the_content_filter', 20 );
/**
* Add a icon to the beginning of every post page.
*
* @uses is_single()
*/
function my_the_content_filter( $content ) {
if ( is_single() )
// Add image to the beginning of each page
$content = sprintf(
'<img class="post-icon" src="%s/images/post_icon.png" alt="Post icon" title=""/>%s',
get_bloginfo( 'stylesheet_directory' ),
$content
);
// Returns the content.
return $content;
}
一个更容易理解的例子:
add_filter( 'the_content', 'add_something_to_content_filter', 20 );
function add_something_to_content_filter( $content ) {
$original_content = $content ; // preserve the original ...
$add_before_content = ' This will be added before the content.. ' ;
$add_after_content = ' This will be added after the content.. ' ;
$content = $add_before_content . $original_content . $add_after_content ;
// Returns the content.
return $content;
}
要查看此示例的实际效果,请将其放入您的 functions.php 中
这实际上是理解 wordpress 和开始编写插件的最重要的一步。如果您真的有兴趣,请阅读上面的链接。
另外,打开您刚才提到的插件文件并查找
过滤器和操作...