Shortcode attributes don’t appear?

You are return two times! The first return exit the function, so your shortcode outputs always “Hello World”. Correct code: function hello( $atts ) { extract( shortcode_atts( array( ‘foo’ => ‘something’, ‘bar’ => ‘something else’, ), $atts ) ); print_r($atts); // Remove, when you are fine with your atts! return ‘Hello, World: ‘.$atts[‘foo’]; } add_shortcode(‘hw’, … Read more

OOP and WordPress shortcode

That is not the way you add an object method as a callback. function make_shortcode() { add_shortcode(‘ShowMsg’, array($this,’ShowMsg’)); } This is explained in the Codex as it pertains to actions and filters, but the principle is the same. I should add that anonymous classes make for painful debugging. Instantiate that class to a variable. It … Read more

problem with shortcodes nesting

put the remove filter to be called first like this, change your span to div or you will have issues with some browsers: remove_filter( ‘the_content’, ‘wpautop’ ); add_filter( ‘the_content’, ‘wpautop’ , 12); function twoColPostcardfn($atts, $content){ extract(shortcode_atts(array( ‘image’=>”, ‘text’=>”, ‘title’=>”, ‘boxlink’=>”, ‘float’=>” ), $atts)); $bob='<div class=”twoColPostcard “>’.$content.'</div>’; return $bob; } add_shortcode( ‘twoColPostcard’, ‘twoColPostcardfn’ ); or change … Read more

wp_list_pages shortcode jumps above previous content

That’s because your list is printed immediately. wp_list_pages() has the echo parameter, which is true by default. Make it false like here: <?php function roofspan_product_childpages() { $list_p = array( ‘sort_column’ => ‘menu_order, post_title’, ‘child_of’ => ’12’, ‘title_li’ => ‘Products: ‘, ‘echo’ => 0 // Note this ); return wp_list_pages( $list_p ); } add_shortcode( ‘product_childpages’, ‘roofspan_product_childpages’ … Read more

return unformatted content in encosing shortcode

The <br /> tags are being added to the content by the wpautop() function. If you run your shortcode before it runs they will not be there. It is added in \wp-includes\default-filters.php with the default priority of 10. add_filter( ‘the_content’, ‘myshortcode’, 1 ); function myshortcode( $atts, $content = null ) { return $content; } wpautop() … Read more

Shortcode output appearing at the top of the page only [duplicate]

Shortcode callback should return it’s output and not echo it. Something like this should work just fine: function get_loggedin_avatar (){ global $current_user; $result=””; if ( is_user_logged_in() ) { get_currentuserinfo(); $result=”<a href=”https://wordpress.stackexchange.com/myaccount”>”. get_avatar( $current_user->ID, 96, left ). ‘</a>’; } return $result; } add_shortcode( ‘loggedinavatar’, ‘get_loggedin_avatar’ );

Shortcode not showing anything

As birgire mentioned in the comments, “you’re missing the return part” to which you replied “how do I add that without escaping the HTML code?” EDIT: Just a clarification. Your code should have worked, as pointed out by dswebsme. I just tested with and without a return, and both work (although returning would be preferred). … Read more