RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts</strong | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.69% (5.89%*) • Home Loan Fixed: 5.39% (6.59%*) • Fixed: 5.39% (6.59%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.69% (6.48%*) • Investment PI: 5.39% (6.59%*)

List Registered WordPress Shortcodes

We have a lot of WordPress shortcodes on this website - [shortcodes count="1"] of them and counting. The number of shortcodes listed above is a live count and will update when a new shortcode is published to the website... and this feature forms part (if not the focus) of the function we've provided below. The other component of the shortcode function will list all your shortcode functions in a list.

The Result

The usage that motivated the code was a means of counting the number of our registered shortcodes. So, [shortcodes count="1"] will output [shortcodes count="1"]. You might optionally list all shortcodes with [shortcodes].

If you run a publishing site and need to provide a resource on shortcode usage, linking to an author-only page with the same slug name detailing shortcode usage (and attributes) might be an easy means of keeping your team educated.

[shortcodes]

The Shortcode Function

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
<?php 
2
/*
3
 Display all Shortcodes Registered on Your WordPress Website
4
 http://www.beliefmedia.com/code/wp-snippets/wordpress-shortcodes
5
*/
6
 
7
function beliefmedia_display_shortcodes($atts) {
8
 
9
  $atts = shortcode_atts(array(
10
    'count' => 0,
11
    'cache' => 3600 * 24 * 4
12
  ), $atts);
13
 
14
   $transient = 'bmsc_' . md5(serialize($atts));
15
   $cachedshortcodes = get_transient($transient);
16
 
17
   if ($cachedshortcodes !== false) {
18
   return $cachedshortcodes;
19
 
20
   } else {
21
 
22
   global $shortcode_tags;
23
 
24
     if ($atts['count']) {
25
       $return = count($shortcode_tags);
26
 
27
       } else {
28
 
29
         foreach ($shortcode_tags AS $key => $value) {
30
           if (!is_array($value)) $return .= '
31
<li>' . $key . ' (' . $value . ')</li>
32
 
33
';
34
         }
35
 
36
         $return = '
37
<ul>' . $return . '</ul>
38
 
39
';
40
 
41
       }
42
 
43
  set_transient($transient, $return, $atts['cache']);
44
  return $return;
45
 }
46
}
47
add_shortcode('shortcodes', 'beliefmedia_display_shortcodes');

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

Shortcode Attributes

count

By default we'll output a list of shortcodes. To display the number (or count) of registered shortcodes, use count="1".

cache

The cache is the length of time we'll cache the result.

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment