How best to apply do_shortcode in media.php for captions

Caption shortcode attributes are merged with defaults using shortcode_atts function like so (see source in media.php): $atts = shortcode_atts( array( ‘id’ => ”, ‘align’ => ‘alignnone’, ‘width’ => ”, ‘caption’ => ”, ‘class’ => ”, ), $attr, ‘caption’ ); So the 3rd $shortcode param is in use with the value of ‘caption’. As you can … Read more

Shortcode doesn’t work with classes

Here’s a simple example using your original code that successfully registers the shortcode. You need to instantiate the Loader class, then call its activate() method. class Shortcodes { public static function notifications_shortcode( $atts, $content = “” ) { return ‘notifications foo foo’; } } class MvcPluginLoader { function __construct() { } } class Loader extends … Read more

Pass shortcode variables to template

You can’t just stick a shortcode somewhere and expect it to do something. It’s basically an buffer that will take whatever code it’s told to generate, compile it exactly how you tell it to, and then output it wherever the shortcode is placed. Take a look at the Shortcode API for more information. As for … Read more

Loading page template into shortcode

get_template_part takes slug as first parameter and not filename. So it should be: get_template_part( ‘template-sponsors’ ); And with more details… This function takes two parameters: get_template_part( string $slug, string $name = null ) And inside of it, the name of a file is built like this: if ( ” !== $name )         $templates[] = “{$slug}-{$name}.php”;       $templates[] = “{$slug}.php”; So, … Read more

Adding span tags within wp_list_pages list items

There is more than one way to accomplish this in WordPress. Option 1: Using the link_before parameter with wp_list_pages. $childpages = wp_list_pages( array( ‘sort_column’ => ‘menu_order’, ‘title_li’ => ”, ‘child_of’ => $parent_id, ‘echo’ => 0, ‘link_before’ => ‘<span class=”fa-li”><i class=”fas fa-spinner fa-pulse”></i></span>’ ) ); Option 2: Create a custom walker, then add the walker parameter … Read more

What is the $atts parameter in shortcode_atts()?

When a user writes a shortcode: [my_shortcode att1=”Attribute 1 value” att2=”Attribute 2 value”] The attributes are passed to the shortcode’s callback function as an array as the first argument: function my_shortcode_callback( $atts ) { // $atts = array( // ‘att1’ => ‘Attribute 1 value’, // ‘att2’ => ‘Attribute 2 value’, // ); } add_shortcode( ‘my_shortcode’, … Read more

Post loop created via shortcode not displaying shortcode in content

get_the_content() does not have the the_content filters applied to it, which is where do_shortcode() is hooked in. Those filters are only applied in the_content(). Those two functions are not simply get/echo versions of each other. get_the_content() is lower level. This is an anomaly in the API, and is that way for historical reasons. For instance, … Read more

How to call custom taxonomy categories with shortcodes

Take a look at category post shortcode to get an idea and here is the plugin with minor modifications to call your post type and taxonomy: // Taxonomy category shortcode function cat_func($atts) { extract(shortcode_atts(array( ‘class_name’ => ‘cat-post’, ‘totalposts’ => ‘-1’, ‘category’ => ”, ‘thumbnail’ => ‘false’, ‘excerpt’ => ‘true’, ‘orderby’ => ‘post_date’ ), $atts)); $output=”<div … Read more

nested Shortcode doesn’t work

From the page you linked: The shortcode parser correctly deals with nested shortcode macros, provided their handler functions support it by recursively calling do_shortcode(): You need to recursively call do_shortcode() on any shortcode handler that could contain nested shortcodes. So for example: function wpse18659_permalink( $atts, $content ){ return ‘<a href=”‘ . get_permalink() . ‘” title=”Permalink … Read more