在 wordpress 插件上使用 the_content 挂钩
using the_content hook on a wordpress plugin
我正在尝试在 wordpress 的每个页面中添加一个包含特定内容的 div。
为此,我正在尝试创建一个插件,将此 div 添加到过滤器中。
我已经创建了插件、修改内容的函数以及使用钩子 "the_content":
对该过滤器的调用
function add_content_filter($content){
$original_content = $content ; // preserve the original ...
$add_pre_content = '<p> This will be added before the content..</p> ' ;
$add_sur_content = '<p> This will be added after the content..</p> ' ;
$content = $add_pre_content . $original_content . $add_sur_content ;
// Returns the content.
return $content;
}
add_filter('the_content', 'add_content_filter');
出于某种原因,即使插件已激活,插件也不会修改内容。我使用的代码来自:
How do wordpress plugins add content?
作为参考。我是否需要执行其他操作才能使代码正常工作?
已解决,可能是由于托管插件中未更新的代码更改所致。它应该像这里写的那样工作。
我正在尝试在 wordpress 的每个页面中添加一个包含特定内容的 div。 为此,我正在尝试创建一个插件,将此 div 添加到过滤器中。 我已经创建了插件、修改内容的函数以及使用钩子 "the_content":
对该过滤器的调用function add_content_filter($content){
$original_content = $content ; // preserve the original ...
$add_pre_content = '<p> This will be added before the content..</p> ' ;
$add_sur_content = '<p> This will be added after the content..</p> ' ;
$content = $add_pre_content . $original_content . $add_sur_content ;
// Returns the content.
return $content;
}
add_filter('the_content', 'add_content_filter');
出于某种原因,即使插件已激活,插件也不会修改内容。我使用的代码来自:
How do wordpress plugins add content?
作为参考。我是否需要执行其他操作才能使代码正常工作?
已解决,可能是由于托管插件中未更新的代码更改所致。它应该像这里写的那样工作。