Reputation: 311
i got the following short lines for showing content in a php file
<p><?php echo $item->post_content; ?></p>
Problem being that when i add a news item from my admin panel in wordpress and use a shortcode the shortcode itself is being displayed instead of the content. Is there any possible way to allow the short code being proccessed in the php file?
It is some kind of news plugin that i must use for the client so cant remove that or use another one.
Upvotes: 0
Views: 477
Reputation: 3326
The do_shortcode() function will manually parse a string for any shortcodes:
echo do_shortcode($item->post_content);
It's because when you execute echo $item->post_content;
by hand, it's not passed through the the_content filter first - which is responsible for things like expanding embedded videos and shortcodes.
There's also a difference between the_content() and get_the_content() - the former hooks into the filter, expands the shortcodes (and echos the content for you) but the latter just returns the unfiltered content as a variable.
Upvotes: 1
Reputation: 1365
There is simple method availalbe in Word Press to execute short code
$content is the short code need to be executed.
for more details please refer:
https://codex.wordpress.org/Function_Reference/do_shortcode
Upvotes: 1