发布

时间:2016-02-23 12:52:21

标签: wordpress wordpress-plugin

我试图在单个帖子内容后添加自定义插件。我尝试使用add_filteradd_action来打印我的插件。

     if(!defined('ABSPATH')) exit;

 function customPlug_plugin_install()
 {

 }

 register_activation_hook(__FILE__, 'customPlug_plugin_install');

 function customPlug_plugin_scripts()
 {
    wp_register_script('customPlug_script', plugin_dir_url(__FILE__), 'js/customplug.js', '1.0', true);
    wp_register_script('customPlug_bootstrap_script', plugin_dir_url(__FILE__), 'js/customplug.js', '1.0', true);
    wp_register_script('customPlug_script', plugin_dir_url(__FILE__), 'js/customplug.js', '1.0', true);
    wp_enqueue_script('customPlug_script');
 }


 function my_plugin($content) {
    $content = "Custom Plugin Content";
    return $content;
 }
 add_action('the_content', 'my_plugin');

但是,如果我发表评论add_filteradd_action

,这只会返回插件内容或the_content

1 个答案:

答案 0 :(得分:0)

您正在覆盖当前内容。您应该使用.

将内容与当前内容连接起来
function my_plugin($content) 
{
    $content. = "Custom Plugin Content";
    return $content;
}