【问题标题】:do_shortcode breaks formattingdo_shortcode 打破格式
【发布时间】:2017-10-28 00:36:54
【问题描述】:

以前有人遇到过这个问题吗?直接从 WordPress 调用简码和通过 functions.php 调用简码会产生不同的结果。

参考这个

图片 1 设计不错,因为它是直接从 WordPress UI 调用的,而图片 2 不知何故弄乱了设计,因为它是从 php (functions.php) 调用的。

附加信息:

  • 当前主题是 DIVI
  • 使用的短代码/插件是 TableMaster

要添加更多信息,我在 WordPress 中有这行简码(如图 2 所示)。

[get_blogs_sc]

在我的functions.php上,我有这个函数,

function GetActiveBlogs($i)
{ 

    $actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

    if (preg_match('/sites/',$actual_link))
    {

        $user_id = get_current_user_id();
        if ($user_id > 0) 
        {

            echo do_shortcode('[tablemaster buttons="true" datatables="true" class="black-header-gray-alternate-rows" sql="some select where user_id = '.user_id.'"]', true);
        }
    }
}


add_shortcode('get_blogs_sc', 'GetActiveBlogs');

但是当我直接从 WordPress 使用简码时:

[tablemaster buttons="true" datatables="true" class="black-header-gray-alternate-rows" sql="some select where user_id = 14]

我页面上的显示看起来不错(如图 1 所示)

我将短代码放入 php-layer 的目的是让我能够从 WordPress 捕获登录用户。

谢谢。

【问题讨论】:

    标签: php wordpress shortcode


    【解决方案1】:

    仅从图像很难诊断出问题所在!没有代码的真正含义。 但是让我们知道do_shortcodeadd_shortcode之间有什么区别

    do_shortcode( string $content, bool $ignore_html = false )
    

    搜索短代码的内容并通过它们的钩子过滤短代码。 它返回(字符串)内容并过滤掉短代码。

    // Use shortcode in a PHP file (outside the post editor).
    echo do_shortcode( '' );
    

    更多信息请查看link

    while add_shortcode 为短代码标签添加挂钩。

    <?php add_shortcode( $tag , $func ); ?>
    

    $标签 (字符串)(必需)要在帖子内容中搜索的简码标签 默认值:无 $函数 (可调用)(必需)找到短代码时运行的挂钩 默认值:无

    它什么都不返回,但是当您在帖子区域编写简码标签时,它会应用简码的功能以获取更多信息检查Link

    【讨论】:

    • 我已添加有关该问题的更多信息。很抱歉遗漏了一些细节。
    • 也许你应该使用 div 和 class="wrap" 并将你的打印代码包装在里面,你可以通过检查 [F12] 来识别两种情况之间的区别
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 2013-01-08
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 2021-07-10
    • 2011-07-14
    相关资源
    最近更新 更多