首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >do_shortcode中断格式

do_shortcode中断格式
EN

Stack Overflow用户
提问于 2017-10-25 20:22:44
回答 1查看 383关注 0票数 0

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

请参考以下内容

图1有很好的设计,因为它是直接从WordPress UI调用的,而图像2在某种程度上扰乱了设计,因为它是从php (functions.php)调用的。

更多信息:

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

为了添加更多信息,我在WordPress中有这行短代码(如图2所示)。

代码语言:javascript
复制
[get_blogs_sc]

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

代码语言:javascript
复制
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使用这些短代码时:

代码语言:javascript
复制
[tablemaster buttons="true" datatables="true" class="black-header-gray-alternate-rows" sql="some select where user_id = 14]

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

我将这些短代码放入php层的目标是让我能够从WordPress中捕获登录用户。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-10-25 20:40:13

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

代码语言:javascript
复制
do_shortcode( string $content, bool $ignore_html = false )

搜索内容的短代码和过滤短代码通过他们的钩子。它返回(字符串)内容,其中包含筛选出的短代码。

代码语言:javascript
复制
// Use shortcode in a PHP file (outside the post editor).
echo do_shortcode( '' );

有关更多信息,请查看链接

add_shortcode为一个短代码标记添加了一个钩子。

代码语言:javascript
复制
<?php add_shortcode( $tag , $func ); ?>

$tag (string) (必需)在post内容默认值中搜索的短代码标记: None $func (可调用)(必需)在找到短代码时运行

它什么也不返回,但是当您在post区域中编写短代码标记时,它应用了短代码函数来获取更多信息,检查链接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46941423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档