dsyk33753
2017-06-26 20:26
浏览 15
已采纳

如何在WordPress中包含发布内容后的php文件

I make plugin for WordPress, and I want to add content php file to end of post content.

This is my plugin file:

add_filter('the_content', 'modlifyContent');

function modlifyContent($content)
{
    global $post;
    $content .= include(plugin_dir_path(__FILE__) . 'my_plugin_test.php');
    return  $content ;

}

but, content php file is added at start of post content.

This is content php file which I want to include to of post content:

<div>
<a href="<?php echo get_post_meta($post->ID, 'url', true); ?>">Enter</a>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sed ipsum augue.</span>
</div>

How I can include content of php file to the end of post content?

图片转代码服务由CSDN问答提供 功能建议

我为WordPress制作插件,我想将内容php文件添加到帖子内容的末尾。

这是我的插件文件:

  add_filter('the_content','modlifyContent'); 
 
function modlifyContent($ content)
 {  
 global $ post; 
 $ content。= include(plugin_dir_path(__ FILE__)。'my_plugin_test.php'); 
返回$ content; 
 
} 
   
 \  n 

但是,内容php文件是在帖子内容的开头添加的。

这是我希望包含在帖子内容中的内容php文件: \ n

 &lt; div&gt; 
&lt; a href =“&lt;?php echo get_post_meta($ post-&gt; ID,'url',true);?&gt;”&gt;输入&lt; / a&gt;  
&lt; span&gt; Lorem ipsum dolor sit amet,consectetur adipiscing elit。  Quisque sed ipsum augue。&lt; / span&gt; 
&lt; / div&gt; 
   
 
 

如何将php文件的内容包含在帖子内容的末尾?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doushang1880 2017-06-26 20:46
    已采纳
    add_filter('the_content', 'modlifyContent');
    
    function modlifyContent($content)
    {
        global $post;
        //output buffer start
        ob_start();
        include(plugin_dir_path(__FILE__) . 'my_plugin_test.php');
        //delete output buffer and returns its content
        $append = ob_get_clean();
        return  $content. $append;
    
    }
    
    打赏 评论

相关推荐 更多相似问题