Last active
September 6, 2015 04:48
-
-
Save nciske/3b186cbc91b48d685679 to your computer and use it in GitHub Desktop.
run_shortcode() is a faster way to call individual shortcodes -- at least 4x faster on a vanilla install, speed increases to 10x or greater with the number of shortcodes registered
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Faster replacement for do_shortcode *for individual shortcodes only* | |
// If you have nested shortcodes or shortcodes intermixed in content, do_shortcode() is the still the way to go. | |
// Inspired by: https://kovshenin.com/2013/dont-do_shortcode/ | |
// WordPress Core Trac Ticket: https://core.trac.wordpress.org/ticket/25435 | |
// Usage | |
// run_shortcode( 'test_shortcode' ); | |
// VS | |
// do_shortcode( '[example_shortcode]' ); | |
// NOT | |
// run_shortcode( 'This is a [test_shortcode].' ); // this will not work | |
// Optionally specify attributes and/or content | |
// run_shortcode( 'test_shortcode', array( 'foo' => 'bar' ), 'content' ); | |
if( ! function_exists( 'run_shortcode' ) ){ | |
function run_shortcode( $tag, $args = null, $content = null ){ | |
global $shortcode_tags; | |
if( isset( $shortcode_tags[ $tag ] ) ){ | |
$func = $shortcode_tags[ $tag ]; | |
} | |
if( ! empty( $func ) && function_exists( $func ) ){ | |
return call_user_func( $func, $args, $content, $tag ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment