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

问题描述 投票:0回答:2

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

如何让短代码显示内容我添加短代码?

谢谢!

wordpress shortcode
2个回答
0
投票

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

它与之前的答案类似,但我认为如果您仍然遇到问题,值得一试。

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

我希望这有帮助。


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' );
© www.soinside.com 2019 - 2024. All rights reserved.