我的 WPdiscuz 短代码出现在页面顶部

My WPdiscuz shortcode appears at the top of the page

我正在使用此代码为我的 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] 时,内容总是显示在页面顶部。

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

简码总是需要return输出。

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' );

我在 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' );

希望对您有所帮助。