简码总是显示默认参数
Shortcode Always Shows Default Parameters
这是我的简码:
function sectWithSidebar($atts, $content, $tag){
//collect values, combining passed in values and defaults
$values = shortcode_atts(array(
'sectionHeading' => 'Section Heading',
'sidebarHeading' => 'Sidebar Heading',
'sidebarText' => 'Sidebar Text',
'buttonURL' => "#",
'classes' => ''
),$atts);
$output = '<div class="container section section-with-sidebar'.$values["classes"].'"><div class="row"><div class="col-sm-12"><h2>'.$values["sectionHeading"].'</h2></div></div><div class="row"><div class="col-md-8 col-sm-12"><span>'.$content.'</span></div><div class="col-md-4 col-sm-12"><div class="sidebar"><div class="sidebar-header">'.$values["sidebarHeading"].'</div><div class="sidebar-content">'.$values["sidebarText"].'<span class="learn-more-button"><a href="'.$values["buttonURL"].'">Learn More</a></span></div></div></div></div></div>';
return $output;
}
add_shortcode('sectionWithSidebar','sectWithSidebar');
我正在尝试这样显示它:
[sectionWithSidebar sectionHeading="Global Health" sidebarHeading="SidebarHeading" sidebarText="SidebarText" buttonURL="http://www.google.com"]
MSIH is a unique school that prepares physicians to address the impact of cultural, economic, political and environmental factors on the health of individuals and populations worldwide. It is the world’s first and only medical school to incorporate core global health courses into all four years of an M.D. program. Classes are small, intimate and challenging. At MSIH, you learn to be not only a doctor, but a skilled physician with a comprehensive view of health around the world.
[/sectionWithSidebar]
然而,它只是显示默认内容,就好像我在将短代码添加到页面时没有定义任何参数一样:
http://109.199.101.20/~newmsih/template-1-with-shortcodes/
简码属性在传递给您的回调之前会被转换为小写。
您的短代码的 sectionHeading
属性将是 $atts
数组中的 sectionheading
。
https://codex.wordpress.org/Function_Reference/add_shortcode
通常情况下,您会看到短代码属性使用下划线而不是驼峰式大小写。
$values = shortcode_atts(array(
'section_heading' => 'Section Heading',
. . .
用法
[sectionWithSidebar section_heading="Global Health" . . .
这是我的简码:
function sectWithSidebar($atts, $content, $tag){
//collect values, combining passed in values and defaults
$values = shortcode_atts(array(
'sectionHeading' => 'Section Heading',
'sidebarHeading' => 'Sidebar Heading',
'sidebarText' => 'Sidebar Text',
'buttonURL' => "#",
'classes' => ''
),$atts);
$output = '<div class="container section section-with-sidebar'.$values["classes"].'"><div class="row"><div class="col-sm-12"><h2>'.$values["sectionHeading"].'</h2></div></div><div class="row"><div class="col-md-8 col-sm-12"><span>'.$content.'</span></div><div class="col-md-4 col-sm-12"><div class="sidebar"><div class="sidebar-header">'.$values["sidebarHeading"].'</div><div class="sidebar-content">'.$values["sidebarText"].'<span class="learn-more-button"><a href="'.$values["buttonURL"].'">Learn More</a></span></div></div></div></div></div>';
return $output;
}
add_shortcode('sectionWithSidebar','sectWithSidebar');
我正在尝试这样显示它:
[sectionWithSidebar sectionHeading="Global Health" sidebarHeading="SidebarHeading" sidebarText="SidebarText" buttonURL="http://www.google.com"]
MSIH is a unique school that prepares physicians to address the impact of cultural, economic, political and environmental factors on the health of individuals and populations worldwide. It is the world’s first and only medical school to incorporate core global health courses into all four years of an M.D. program. Classes are small, intimate and challenging. At MSIH, you learn to be not only a doctor, but a skilled physician with a comprehensive view of health around the world.
[/sectionWithSidebar]
然而,它只是显示默认内容,就好像我在将短代码添加到页面时没有定义任何参数一样: http://109.199.101.20/~newmsih/template-1-with-shortcodes/
简码属性在传递给您的回调之前会被转换为小写。
您的短代码的 sectionHeading
属性将是 $atts
数组中的 sectionheading
。
https://codex.wordpress.org/Function_Reference/add_shortcode
通常情况下,您会看到短代码属性使用下划线而不是驼峰式大小写。
$values = shortcode_atts(array(
'section_heading' => 'Section Heading',
. . .
用法
[sectionWithSidebar section_heading="Global Health" . . .