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

如何在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?

  • 写回答

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;
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?