I'm creating a shortcode as part of a plugin that I'm calling in a template like this:
do_shortcode('[shortcodename title="monkeys"]');
The function looks like this to begin with:
function shortcodename_function($atts = []) {
// stuff
}
Inside the function, I'm trying to print_f the $atts out before running shortcode_atts to confirm they're there, but I'm getting nothing. It's like it's flat out ignoring the attributes I apply. Once I run shortcode_atts, I get my defaults in and these appears correctly in a print_f.
If I pop the shortcode into the content of a post with attributes, it outputs these fine. Is there some element of do_shortcode that is ignoring my attributes? Or is there something to do with the order of things being initialised? Attributes aren't essential for this, but they'd be nice and I'd like to know why it's not working the way I'm thinking it should.
The whole sanitised thing looks like this:
function shortcodename_function($atts = []) {
$pairs = array(
'title' => 'bananas'
);
$a = shortcode_atts($pairs, $atts);
}
and again, in the template:
echo do_shortcode('[shortcodename title="monkeys"]');
this shortcode is set up within a plugin, so not sure if that makes a difference.
edited: added an 'echo' to better represent how it's being displayed
echo do_shortcode('[shortcodename title="monkeys"]');
isn't working? ...you have to useecho
which I don't see/read you are using?! Take a quick look in the Codex please.