RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.38% (6.14%*) • Home Loan Fixed: 5.44% (6.26%*) • Fixed: 5.44% (6.26%*) • Variable: 5.38% (6.14%*) • Investment IO: 5.69% (6.52%*) • Investment PI: 5.49% (5.98%*)

Display Active WordPress Plugins in a Post or Page with Shortcode

Display Active WordPress Plugins in a Post or Page with Shortcode

While I don't know exactly why you would want to display your active WordPress plugins for the world to see, there may come a time where it's necessary. The WordPress shortcode function on this page will do just that: render all your active plugins in a list (with optional link back to the plugin page). We'll provide a few different ways of accomplishing the same thing.

The Result

The shortcode of [showplugins] returns the following list:

  • akismet
  • crayon-syntax-highlighter
  • hiztory
  • beliefmedia
  • beliefmedia-examples
  • lipsum
  • metar
  • shortt
  • simple-audio-player
  • simple-post-counter
  • wp-super-cache

In our case, there's 11 plugins. However, three of those are ours and aren't hosted with WordPress. The plugin beliefmedia-examples, for example, is a plugin we use just to host example code that isn't part of our own site core. The next function addresses this in a couple of different ways.

WP Shortcode Functions

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

get_option()

The first function makes use of get_option to retrieve the plugin array.

1
<?php 
2
/*
3
 Display Active WordPress Plugins in a Post or Page with Shortcode
4
 http://www.beliefmedia.com/display-wordpress-plugins
5
*/
6
 
7
function beliefmedia_active_site_plugins() {
8
 
9
  /* Get active plugins option */
10
  $plugins = get_option('active_plugins');
11
 
12
    /* Create list */
13
    foreach($plugins as $key => $value) {
14
       $string = explode('/', $value);
15
       $list .= '<li>' . $string[0] . '</li>';
16
    }
17
 
18
 return '<ul>' . $list . '</ul>';
19
}
20
add_shortcode('showplugins', 'beliefmedia_active_site_plugins');

wp_get_active_and_valid_plugins()

Rather than use get_option, you may choose to use wp_get_active_and_valid_plugins() . Rather than return just the directory/filename.php, it returns the full path in its array. The function, located in wp-includes/load.php , will first do what we did above - use get_option to return an array - but then it continues to check the validity of the file and ensures it's not a default network plugin. Interestingly, it first checks for the old hackfile.php (I'm surprised WP still include it).

The shortcode of [showactivevalid] will return the same list as above.

1
<?php 
2
/*
3
 Display Active WordPress Plugins in a Post or Page with Shortcode
4
 http://www.beliefmedia.com/display-wordpress-plugins
5
*/
6
 
7
function beliefmedia_active_valid_site_plugins() {
8
 
9
10
 
11
  foreach($plugins as $key => $value) {
12
    $dir = pathinfo($value);
13
    $dir = end(explode('/', $dir['dirname']));
14
    $list .= '<li>' . $dir . '</li>';
15
  }
16
 
17
 return '<ul>' . $list . '</ul>';
18
}
19
add_shortcode('showactivevalid', 'beliefmedia_active_valid_site_plugins');

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.

Linking back to Plugins on WordPress.org

Sometimes you might want to link the plugin back to WordPress.org. However, WordPress doesn't discriminate against plugins installed from their own library or something you've written yourself, or something you've downloaded from elsewhere. So, to circumvent this we can create an $exclude array that'll give us a crude means of checking whether the plugin link should be created or just returned by name.

1
<?php 
2
/*
3
 Display Active WordPress Plugins in a Post or Page with Shortcode
4
 http://www.beliefmedia.com/display-wordpress-plugins
5
*/
6
 
7
function beliefmedia_active_valid_link_plugins() {
8
 
9
  /* Get the plugins.. */
10
11
 
12
  /* Internal plugins listed in an exclude array */
13
  $exclude = array('beliefmedia','beliefmedia-examples','shortt');
14
 
15
  foreach($plugins as $key => $value) {
16
    $dir = pathinfo($value);
17
    $dir = end(explode('/', $dir['dirname']));
18
    $return .= (!in_array($dir, $exclude)) ? '<li><a href=&quot;https://wordpress.org/plugins/' . $dir . '/&quot; rel=&quot;nofollow&quot; title=&quot;' . $dir . '&quot;>' . $dir . '</a></li>' : '<li>' . $dir . '</li>';
19
  }
20
 
21
 return '<ul>' . $return . '</ul>';
22
}
23
add_shortcode('linkactivevalid', 'beliefmedia_active_valid_link_plugins');

The result is as follows (sample only):

Considerations

  • While there's not much use to this code, we use it to query client websites (via an API built into a company plugin) that returns plugin data so it can be surveyed at times when a security exploit is identified. We also use it to simply tally the number of plugins they have installed.

Download


Title: Display Active WordPress Plugins (WP Plugin)
Description: Display Active WordPress Plugins in a Post or Page with Shortcode
  Download • Version 0.2, 1.6K, zip, Category: WordPress Plugins (General)
WordPress Shortcodes, (742.0B)    

■ ■ ■

 
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 ]

RELATED READING

Like this article?

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

Leave a comment