2017-04-27 3 views
0

Das ist mein Shortcode:Shortcode Zeigt immer Standardparameter

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'); 

Ich versuche es so anzuzeigen:

[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] 

Aber es zeigt nur den Standardinhalt, als ob ich ‚didn t Parameter definieren, wenn der Shortcode zur Seite hinzugefügt wird: http://109.199.101.20/~newmsih/template-1-with-shortcodes/

+0

Gelöst: nicht Großbuchstaben in der Parameternamen haben. lol – michaelnewsomejr

Antwort

1

Shortcode-Attribute werden vor der Übergabe in Kleinbuchstaben konvertiert zu Ihrem Rückruf.

Das sectionHeading Attribut auf Ihrem Shortcode wäre sectionheading im $atts Array.

https://codex.wordpress.org/Function_Reference/add_shortcode

Normalerweise würden Sie Unterstrichen statt Kamel Fall gebraucht für Shortcode-Attribute.

$values = shortcode_atts(array(
    'section_heading' => 'Section Heading', 
    . . . 

Nutzungs

[sectionWithSidebar section_heading="Global Health" . . .