Why does WP display the actual shortcode not the string that’s meant to replace it?

Screenshot showing activated wordpress plugin

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

<?php
/**
 * @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
*/

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

?>

The plugin is activated:

The shortcode is in the post:

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?

Read more here:: Why does WP display the actual shortcode not the string that’s meant to replace it?

Leave a Reply

Your email address will not be published. Required fields are marked *