Reputation: 63
I have create a custom plugin which create short code for some content, but when i used in a page it not display content it's show "[BhContent]" as normal text. code I'm using given below. Please anyone help me to short out this.
function bhavin_content(){
echo "Hello bhavin";
}
//[BhContent]
add_shortcode( 'BhContent', 'bhavin_content' );
Thanks in advance!
Upvotes: 0
Views: 127
Reputation: 4328
Take a look at the documentation here. You are supposed to return the content that is to be output, not output it yourself.
function bhavin_content(){
return "Hello bhavin";
}
add_shortcode( 'BhContent', 'bhavin_content' );
See this quote from the documentation:
Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results. This is similar to the way filter functions should behave, in that they should not produce expected side effects from the call, since you cannot control when and where they are called from.
Upvotes: 1