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

报告相同问题?

悬赏问题

  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services