Tagged: shortcode
Not rendering – just displaying the shortcode in the page. What is wrong?
In my child theme > functions.php
function my_shortcode_function(){
$str = "this is my text.";
return $str;
}
add_filter( 'show-my-text', 'my_shortcode_function' );
In a text block of a page i put:
[show-my-text]
The page displays: [show-my-text]
What could cause this?
Found the problem I think. The code in functions.php to add the shortcode needs to be:
add_shortcode( 'show-my-text', 'my_shortcode_function' );
`
NOT what I had:
add_filter( 'show-my-text', 'my_shortcode_function' );
`
Don’t know how I ended up with add_filter.
Hi!
Yes, that is the issue.
For more information, please see – https://codex.wordpress.org/Shortcode_API
Best regards,
Yigit