How to check if this is the nth instance of a given shortcode in a post

If you’re using a class, it would be class MyShortcode { static $instance = 0; function __construct($args = array()) { add_action( ‘init’, array(&$this, ‘init’) ); } function init() { add_shortcode(‘myshortcode’, array(&$this, ‘shortcode’)); } static function shortcode($atts) { //this is the code of your shortcode // you can increment your counter self::$instance++; } }

Add_shortcode as a Class to pass arguments to a function

To create multiple shortcodes, you can get the default values from a static attribut of the class. This code create 2 shortcodes myshortcode1 and myshortcode2. In the included files, you can read variables $_atts, $content and $tag class MyLittleClass { public static $shortcodes; public static function init() { self::$shortcodes = [ “myshortcode1” => [ “defaultValues” … Read more

Is shortcode_unautop() broken?

It seems the function is broken. The issue is in trac: https://core.trac.wordpress.org/ticket/14050 I am using this to solve the problem temporarily: https://core.trac.wordpress.org/attachment/ticket/14050/plugin.php . This code still fails some of the tests used, but it completely resolves the issue I described, so I will use it unless I find something practical that it breaks.

How to enqueue script based on post category?

Inside your theme’s functions.php add something like this: function my_conditional_enqueue_script() { global $post; if (is_single($post->ID) && in_category(‘mouse’, $post->ID)) { wp_enqueue_script(‘mousescript’); } } add_action(‘wp_enqueue_scripts’, ‘my_conditional_enqueue_script’); Also, make sure you use wp_register_script before you attempt to enqueue.

How navigation works in custom loop within shortcode?

if you look at previous_posts_link() and next_posts_link() in source, you’ll see why they don’t work, they use the global $paged and $wp_query vars to format the links and determine whether or not they appear. you’ll have to roll your own pagination using the paged and max_num_pages vars in your custom query.

Turn a snippet of HTML and PHP into a shortcode

When you want to turn a snippet into a shortcode, you have to return a string. You cannot use echo or print anything in any other way. Also, always escape your data, and check if there are actually values. I have used the HEREDOC syntax here, because it is easy to read: add_shortcode( ‘taobao’, ‘taobao_shortcode’ … Read more

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