我的WPdiscuz简码显示在页面顶部

时间:2019-04-02 17:58:44

标签: wordpress shortcode

我正在使用以下代码为我的WPdiscuz插件生成简码:

function my_wpdiscuz_shortcode() {
    if(file_exists(ABSPATH . 'wp-content/plugins/wpdiscuz/templates/comment/comment-form.php')){
        include_once ABSPATH . 'wp-content/plugins/wpdiscuz/templates/comment/comment-form.php';
    }
}


add_shortcode( 'wpdiscuz_comments', 'my_wpdiscuz_shortcode' );

但是,在添加简码[wpdiscuz_comments]时,其内容始终显示在页面顶部。

如何使简码显示添加简码中的内容?

谢谢!

2 个答案:

答案 0 :(得分:0)

简码总是需要返回输出。

function my_wpdiscuz_shortcode() {
    if(file_exists(ABSPATH . 'wp-content/plugins/wpdiscuz/templates/comment/comment-form.php')){
        ob_start();
        include_once ABSPATH . 'wp-content/plugins/wpdiscuz/templates/comment/comment-form.php';
        return ob_get_contents();
    }
}
add_shortcode( 'wpdiscuz_comments', 'my_wpdiscuz_shortcode' );

答案 1 :(得分:0)

我在Beaver Builder Facebook小组上看到您有一些问题,显示为重复,仍然以为如此,以为我会共享用于WP Shortcodes的代码,而该代码需要另一个PHP脚本。

这与先前的答案类似,但是我认为如果您仍然遇到问题,则值得尝试。

function my_wpdiscuz_shortcode() {
    $html = "";
    if(file_exists(ABSPATH . 'wp-content/plugins/wpdiscuz/templates/comment/comment-form.php')){
        ob_start();
        include_once ABSPATH . 'wp-content/plugins/wpdiscuz/templates/comment/comment-form.php';
        $html = ob_get_clean();
    }
    return $html;
}
add_shortcode( 'wpdiscuz_comments', 'my_wpdiscuz_shortcode' );

我希望这会有所帮助。

相关问题