它们与Filters,Actions实现它,并挂接到他们。
在你的情况 - 与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_pre_content . $original_content . $add_sur_content ;
// Returns the content.
return $content;
}
在行动中看到这个例子中,把它放在你的functions.php
这实际上是理解wordpress最重要的一步,并开始编写插件。如果您真的有兴趣,请阅读上面的链接。
此外,打开你刚才提到的插件文件并查找 Filters和Actions ...
好感谢!对wordpress来说很新,所以我是一个建立插件的途径,但这非常有帮助!你摇滚。 –
好。祝你编写插件。如果答案有帮助,请尝试接受它。 (得分之下的小绿色“v”) –