I wanted to add shortcode from the text editor of wordpress post.I have added following short code in the post of wordpress:
<img alt="" src="[template_url]/images/ic_sol_1a.png" />
Here [template_url]
is the shortcode i wanted to use it was not working. when i see it in the post page it render the text not the short code response. Somewhere i saw a solutions like adding following line to functions.php of theme:
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
But still after adding these lines i am unable to make shortcode work. What could be the possible reason?
my shortcode function is like this:
function my_template_url() {
return get_bloginfo('template_url');
}
add_shortcode("template_url", "my_template_url");
You will need to use the
get_bloginfo()
to return the value as in your example and make sure to usethe_content()
to print the value to the page. If you use one of the API methods such asget_the_content()
then thedo_shortcode
filter is not run. If you want to apply it use the following:You do not need the
add_filter()
lines.After lots of headache and with the help of @doublesharp and @Nathan Dawson comments/answers we figured out Problem was inside
single.php
file of theme we were getting the content of post usingget_the_content
function. By changing it tothe_content()
function sortcodes start working. Please note that shortcode will not work in the visual editor of WordPress post on admin site but when you see the post actually in the browser by going to that post you can see it working.