WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use shortcode in my page, I'm starting with a simple test.

In functions.php:

function HelloWorldShortcode() {
    return '<p>Hello World!</p>';
add_shortcode('helloworld', 'HelloWorldShortcode');

In index.php:


This doesn't produce <p>Hello World!</p>. Instead I just get the text [helloworld].

How can I get shortcodes to work in a PHP document?

share|improve this question
up vote 1 down vote accepted

Referering to the Shortcodes API you can do

echo do_shortcode('[helloworld]');

if your shortcode not in post. Or you can do

echo apply_filters('the_content', '[helloworld]');

but this will also bring other filters to work on your shorcode return html.

share|improve this answer


echo do_shortcode( '[helloworld]' );

if you're going to use it in your template / PHP code.

share|improve this answer

Shortcodes are parsed through the function do_shortcode(). In some cases this function is applied as a callback automatically, for example when you are using the_content().

To invoke the shortcode parser use something like this:

echo do_shortcode( 'I want to say: [helloworld]' );

But I would not use a shortcode like this, calling the handler without do_shortcode() is faster and easier to read.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.