Shortcode with product catgory counter

Try this: (add it to the theme’s main functions.php file) add_shortcode( ‘products-counter’, ‘products_counter’ ); function products_counter( $atts ) { $atts = shortcode_atts( [ ‘category’ => ”, ], $atts ); $taxonomy = ‘product_cat’; if ( is_numeric( $atts[‘category’] ) ) { $cat = get_term( $atts[‘category’], $taxonomy ); } else { $cat = get_term_by( ‘slug’, $atts[‘category’], $taxonomy ); … Read more

Some doubts about gallery shortcode in WordPress

If you want to display the attached image gallery, from another post, you can use: where the custom id attribute is the post ID. If you want limit the number of items in a gallery, there seems to be a plugin available on wordpress.org called Limit parameter for gallery shortcode (no affiliation). It uses the … Read more

Creating a WordPress shortcode

Separate out your logic from the string you want to return: <?php // Adding a shortcode to return each author’s social media links function funcauthor_social( $atts ){ $meta_socialgr = esc_url(get_post_meta( $post->ID, ‘author_goodreads’, true )); $output=”<div class=”authorsocial”><h5>Connect, Share &amp; Follow</h5><ul>”; if (!empty($meta_socialgr)) { $output .= ‘<li><a href=”‘.$meta_socialgr.'”><img src=”http://fiddlehead.milkbossindustries.com/files/goodreads.jpg”></a></li>’; } $output .= ‘</ul></div>’; return $output; } add_shortcode( … Read more

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.

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