I'm attempting to add a shortcode wordpress sites using a custom plugin. No matter how I try to register or call this, the shortcode does not seem to render.
I am using the default 2020 theme from Wordpress to test this.
This is the code that adds the shortcode:
add_shortcode(
'test',
function () {
return 'test output';
}
);
If I manually check this on the template:
var_dump(shortcode_exists('test'));
the following is generated on a page load:
boolean true
However, if the following is added to the page content, it does not load:
[test]
I have also added the following to the theme functions.php
add_filter( 'widget_text', 'do_shortcode' );
However, as this is not within a widget (just post text) I did this to eliminate this possibility. It did not help.
Edit: I also added the following to the page:
do_shortcode(['test']);
This produces the required output.
Every single tutorial does the above, pretty much verbatim. What am I missing?
To be clear: Using [test] in content to show the shortcode inside post body content is the required behaviour.


do_shortcodeto elimiate the possibility of a content parsing issue. I want to call this through content as per the usual method:[test]or[shortcode_name]. - elb98rm