For some reasons every shortcode, that I try to add to functions.php, displays only default attribute value and ignores what I specify in a post. E.g.:
function my_shortcode( $atts ) {
extract( shortcode_atts(
array(
'id' => '18',
), $atts )
);
return $id;
}
add_shortcode( 'sc', 'my_shortcode' );
So I use shortcode [sc id="81"]
and expect echoing 81
but I get 18
. BTW I use child theme, and latest version of wordpress. I’m really stuck. Thanks for any help.
I just tried your exact code, putting the PHP code you pasted above in my theme’s
functions.php
file, and inserting the shortcode as you typed[sc id="81"]
in to a page in my site, publishing the page, and it correctly outputted a value of81
on my published page.So something in your theme or a plugin must be conflicting with it.
Try changing to one of the default WordPress themes and testing it again, and/or disabling your plugins.
I suspect it could be a conflict because the parameter is named ‘
id
‘ – so you could also try using a different parameter name (eg. ‘myid
‘).