Reputation: 4262
I created my first custom shortcode in my theme, adding the following lines in functions.php
function ec_toggle_content($atts, $content = null){
$togtit='Title test';
extract(shortcode_atts(array('togtit'=> ''), $atts));
$output .= '<h4 class="toggletrg">'.$title.' <i class="fa fa-plus right toggleicon"></i><i class="fa fa-minus right toggleicon hidden"></i></h4>';
$output .= '<div class="togglecont">';
$output .= do_shortcode($content);
$output .= '</div>';
return $output;
add_shortcode('toggle', 'ec_toggle_content');
}
and when I edit one of my posts adding the shortcode i.e.
[toggle togtit="comn pleas work"]bla bla bla text[/toggle]
It just renders as plain text... (for reference, http://ipfcommunity.wdemo.it/aggiornamenti/news/respirare-sottacqua-piccoli-esercizi-sopravvivenza-spirituale/)
I really can't figure out how to make it work, I read that the most common problem could be that I don't render using get_content() to retrieve the post content, but that's what I do so I can't find any further advice.
Upvotes: 0
Views: 589
Reputation: 4262
The following guide was misleading mosaikweb.com/toggle-plus-shortcode
Basically as hinted by FMashiro, i moved
add_shortcode('toggle', 'ec_toggle_content');
at the top of my sample code, the working result is
add_shortcode('toggle', 'ec_toggle_content');
function ec_toggle_content($atts, $content = null){
$togtit='Title test';
extract(shortcode_atts(array('togtit'=> ''), $atts));
$output .= '<h4 class="toggletrg">'.$title.' <i class="fa fa-plus right toggleicon"></i><i class="fa fa-minus right toggleicon hidden"></i></h4>';
$output .= '<div class="togglecont">';
$output .= do_shortcode($content);
$output .= '</div>';
return $output;
}
Upvotes: 1