I'm learning how to create shortcodes. I have the following plugin:

 * @package Foobar
 * @version 1.0
Plugin Name: Foobar
Plugin URI: www.example.com
Description: Shortcode something something
Author: Me
Version: 1.0
Author URI: www.example.com

function foobar_func( $atts ){
    return "foo and bar";
add_shortcode( 'foobar', 'foobar_func' );


The plugin is activated:

Screenshot showing activated wordpress plugin

The shortcode is in the post:

post editor

I expect [foobar] to be replaced with "foo and bar". Instead the post is displayed as:

screenshot of post

What have I missed? Why isn't the short code tag being replaced?

  • 1
    And if you place it on its own line? Making sure it looks exactly as it should from the non-visual raw text view? And that all caching plugins are turned off? Also, the trailing ?> is unnecessary and is considered bad practice as any whitespace afterwards can cause problems for some versions of PHP
    – Tom J Nowell
    Mar 8, 2018 at 22:30
  • I moved it to its own line. No caching plugins. No HTML tags etc. in the raw text view -- looks how it should be. Still the same behaviour. Mar 8, 2018 at 22:42
  • hmmm and the plugin is activated on the same blog on the same server? This is highly suspicious, that code should work
    – Tom J Nowell
    Mar 8, 2018 at 22:46
  • 1
    Also, why is your Hello in all caps on the frontend? Are you sure you're not running various plugins on the content that're interfering? Or modified the frontend to not use the_content?
    – Tom J Nowell
    Mar 8, 2018 at 22:49
  • 1
    Yes, I had written another plugin that modified the_content. Mar 8, 2018 at 22:58

1 Answer 1


The cause was obvious. I had earlier created a plugin that uppercased the entire post. The shortcode was not recognised because it was in all caps -- just as the screenshot shows. Disabling that plugin allowed the shortcode to work as intended.

  • 5
    You can uppercase text using CSS via text-transform: uppercase;
    – Tom J Nowell
    Mar 8, 2018 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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