I’ve created a short code that I’m trying to pass an attribute into, but I don’t seem to be receiving the value on the other end.
Here’s what I’ve got below;
function list_display($atts) {
extract( shortcode_atts(
array(
'pageName' => 'No Page Received',
), $atts )
);
echo $pageName;
add_shortcode('list-briefings-display', 'list_display');
}
and the shortcode being used is
[list-display pageName="My Page Name"]
and I’m running a require_once from functions.php
require_once ( TEMPLATEPATH. '/includes/list-display.php' );
But what I’m seeing on the screen is ‘No Page Received’, can anyone think of something I might’ve missed?
There is more content being generated by the shortcode, which I have’t included, that’s rendering fine. So it just seems to be something to do with how I’ve passed the attribute.
Any help is appreciated.
You’ll probably want to use “return” instead of “echo” if you’re using the shortcode within pages and posts.. Echo could cause it to send output to the screen a little too early and won’t end up exactly where you may be expecting it to be.
There was also a little formatting issue in your code that I’ve corrected, mainly trying to use add_shortcode() from within the very same function you’re trying to reference. I also changed the first parameter of add_shortcode() to the shortcode you were trying to use in your example.