WordPress Shortcodes

A shortcode that simply returns something

add_shortcode('return_something', 'return_something_shortcode');

function return_something_shortcode() {
    return 'something';

Using ob_start

function return_something_shortcode() {
    $output_string = ob_get_contents(); 
    return $output_string; 

Using the shortcode’s content

function use_shortcode_content($atts, $content = null) {
    // eg. echo $atts['id'];
    return $content;

Using PHP to execute a shortcode

echo do_shortcode('[return_something]');

Learning Resources

  • Getting Started With WordPress Shortcodes article.
  • How to create your own WordPress shortcodes article.


Post A Comment

Anti-Spam Quiz: