Have been looking at various tutorials and answers here and elsewhere and just can’t get this to work. Just trying to display a simple output from a shortcode as below, but it is just outputting the actual shortcode tag to the page instead of the content from the shortcode
Functions.php
<?php
function welcome_roundels_func(){
return "testing";
}
add_shortcode( 'welcome_roundels', 'welcome_roundels_func' );
?>
add_action( 'init', 'register_shortcodes');
Usage
[welcome_roundels]
Is there anything else I have to do to enable shortcodes, or should the above work?
Edit
I am also using the below code to output the content
$welcomePage = get_post( 5 );
echo $welcomePage -> post_content;
Your problem is here:
Shortcodes are processed on display by via a filter on
the_content
which is called by the functionthe_content()
. You’ve bypassed that functionality and areecho
ing the raw post data.You need to output your code using a proper Loop or explicitly process the shortcode.