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

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

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

I dont want to show shortcode in tag

A) If you want to show the shortcode syntax you can try to write it with double brackets in the editor: <pre>[[shortcode foo=”bar”]]</pre> It will then display as <pre>[shortcode foo=”bar”]</pre> on your frontend and it will not activate the shortcode callback. B) Or if you want some extra formatting, you could define your own pretty … Read more

Shortcode output is screwed up when arrow symbol “

This issue was introduced in WP 4.2.3 with the introduction of the do_shortcodes_in_html_tags() function, which does a HTML parse of content to protect against content containing shortcodes authored by untrustworthy contributors/authors who by specially crafting shortcode attributes can create XSS exploits. If that security situation doesn’t apply to you and you only want this to … Read more

How do I require a file in a shortcode?

Shortcodes are expected to return content, not echo it out. So if your shortcode_file.php file is straight html, it’s considered being echoed. If that’s the case, you could do something like : function shortcode_name(){ ob_start(); require_once ( plugin_dir_path(__FILE__) . ‘/shortcode_file.php’); $content = ob_get_clean(); return $content; };

Changing playlist shortcode thumbnail sizes?

Demo Plugin – Fixed Size Here’s one suggestion as a demo plugin (PHP 5.4+): <?php /* Plugin Name: Custom Playlist Thumb Size */ namespace WPSE238646\PlaylistThumbSize; add_shortcode( ‘playlist’, function( $atts = [], $content=”” ) { add_filter( ‘wp_get_attachment_image_src’, __NAMESPACE__ . ‘\\src’ , 10, 3 ); $out = wp_playlist_shortcode( $atts, $content ); remove_filter( ‘wp_get_attachment_image_src’, __NAMESPACE__ . ‘\\src’ ); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)