Counter Number Shortcode

Below, you’ll find a detailed guide on how to add the Counter Number Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Counter Number Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Counter Number Plugin and the shortcodes it provides:

Plugin Icon
Counter Number

"Counter Number is a unique plugin for WordPress that adds dynamic number counters to your site. It's perfect for showcasing statistics, achievements or any important numbers in an engaging way."

★★★★☆ (175) Active Installs: 10000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [COUNTER_NUMBER]

Counter Number [COUNTER_NUMBER] Shortcode

The ‘COUNTER_NUMBER’ shortcode is a powerful tool in the PHP/Wordpress ecosystem. It’s designed to retrieve and display a specific counter number based on its ID. When used, it checks if the ‘id’ attribute is set. If it is, it assigns the ‘id’ value to the ‘counter_id’ variable, otherwise, it assigns an empty string. It then requires the ‘content.php’ file and resets the WordPress query. This ensures that the shortcode doesn’t interfere with the main query on your page. The output is then returned and cleaned up using ‘ob_get_clean()’ function, which effectively ends output buffering and turns off output buffering. This is crucial for preventing any unwanted side effects. In conclusion, the ‘COUNTER_NUMBER’ shortcode is a simple yet effective way to display specific counter numbers on your WordPress site.

Shortcode: [COUNTER_NUMBER]

Parameters

Here is a list of all possible COUNTER_NUMBER shortcode parameters and attributes:

  • id – The unique identifier for the specific counter number display

Examples and Usage

Basic example – A simple shortcode usage to display a counter by referencing its ID.

[COUNTER_NUMBER id=1 /]

Advanced examples

Displaying a counter by referencing an ID that does not exist. In this case, since no ID is provided or the provided ID does not exist, the counter will not be displayed.

[COUNTER_NUMBER id=9999 /]

Using the shortcode without an ID. Since no ID is provided, the counter will not be displayed.

[COUNTER_NUMBER /]

Please note that in all these examples, the ‘id’ parameter is used to specify which counter to display. If no ‘id’ parameter is provided or the provided ‘id’ does not exist, the counter will not be displayed.

PHP Function Code

In case you have difficulties debugging what causing issues with [COUNTER_NUMBER] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('COUNTER_NUMBER','ShortCNS');

Shortcode PHP function:

function ShortCNS($Id){
	ob_start();
	if(!isset($Id['id'])){
		$counter_id= "";
	}
	else{
		$counter_id = $Id['id'];
	}
	require("content.php");	
	wp_reset_query();
	return ob_get_clean();	
}

Code file location:

counter-number-showcase/counter-number-showcase/templates/shortcode.php

Conclusion

Now that you’ve learned how to embed the Counter Number Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *