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

图1有很好的设计,因为它是直接从WordPress UI调用的,而图像2在某种程度上扰乱了设计,因为它是从php (functions.php)调用的。
更多信息:
为了添加更多信息,我在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层的目标是让我能够从WordPress中捕获登录用户。
谢谢。
发布于 2017-10-25 20:40:13
很难仅仅从图像中诊断出问题所在!没有代码的真正含义。但是让我们知道do_shortcode和add_shortcode之间有什么区别
do_shortcode( string $content, bool $ignore_html = false )搜索内容的短代码和过滤短代码通过他们的钩子。它返回(字符串)内容,其中包含筛选出的短代码。
// Use shortcode in a PHP file (outside the post editor).
echo do_shortcode( '' );有关更多信息,请查看链接
而add_shortcode为一个短代码标记添加了一个钩子。
<?php add_shortcode( $tag , $func ); ?>$tag (string) (必需)在post内容默认值中搜索的短代码标记: None $func (可调用)(必需)在找到短代码时运行
它什么也不返回,但是当您在post区域中编写短代码标记时,它应用了短代码函数来获取更多信息,检查链接。
https://stackoverflow.com/questions/46941423
复制相似问题