Wordpress 简码显示问题
Wordpress Shortcode Display Issue
我不想使用短代码在页面上显示所有 wordpress 类别。
我的代码:
function catpage_function(){
$variable = wp_list_categories( array(
'show_count' => true,
'orderby' => 'name',
'style' => 'none',
'hide_empty' => 0
) );
return $variable;
}
add_shortcode('catpage', 'catpage_function' );
但是当我将短代码 [catpage] 插入页面时,它没有显示在标题下。代码显示在标题上方。
Screenshot of the site
我能做什么?
在简码函数 catpage_function
上,您应该 return 字符串(将 echo
设置为 false
):
function catpage_function(){
$variable = wp_list_categories( array(
'show_count' => true,
'orderby' => 'name',
'style' => 'none',
'hide_empty' => 0,
'echo' => 0,
) );
return $variable;
}
add_shortcode('catpage', 'catpage_function' );
尝试使用 ob_start() 正确呈现短代码中的 HTML
<?php
function catpage_function(){
ob_start();
$variable = wp_list_categories( array(
'show_count' => true,
'orderby' => 'name',
'style' => 'none',
'hide_empty' => 0,
'echo' => 0,
) );
ob_end_clean();
return $variable;
}
add_shortcode('catpage', 'catpage_function' );
我不想使用短代码在页面上显示所有 wordpress 类别。
我的代码:
function catpage_function(){
$variable = wp_list_categories( array(
'show_count' => true,
'orderby' => 'name',
'style' => 'none',
'hide_empty' => 0
) );
return $variable;
}
add_shortcode('catpage', 'catpage_function' );
但是当我将短代码 [catpage] 插入页面时,它没有显示在标题下。代码显示在标题上方。
Screenshot of the site
我能做什么?
在简码函数 catpage_function
上,您应该 return 字符串(将 echo
设置为 false
):
function catpage_function(){
$variable = wp_list_categories( array(
'show_count' => true,
'orderby' => 'name',
'style' => 'none',
'hide_empty' => 0,
'echo' => 0,
) );
return $variable;
}
add_shortcode('catpage', 'catpage_function' );
尝试使用 ob_start() 正确呈现短代码中的 HTML
<?php
function catpage_function(){
ob_start();
$variable = wp_list_categories( array(
'show_count' => true,
'orderby' => 'name',
'style' => 'none',
'hide_empty' => 0,
'echo' => 0,
) );
ob_end_clean();
return $variable;
}
add_shortcode('catpage', 'catpage_function' );