WordPress如何在发布内容后包含php文件
问题描述:
我为WordPress制作插件,并且希望将内容php文件添加到帖子内容结尾。WordPress如何在发布内容后包含php文件
这是我的插件文件:
add_filter('the_content', 'modlifyContent');
function modlifyContent($content)
{
global $post;
$content .= include(plugin_dir_path(__FILE__) . 'my_plugin_test.php');
return $content ;
}
但是,内容php文件在帖子内容的开始加入。
这是内容的PHP文件,我想包括对文章内容的:
<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>
我怎么能包括对文章内容的末尾PHP文件的内容?
答
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;
}