0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

3 Comments

Hi thanks, problem being the code differs, example [insert page='a page' display='content'] and this "a page" will be different everytime
Hi If you can post code snippet then i can help you in better way.
Hi, thanks for your help, i got it solves aboce, was just needed to do a do_shortcode, i just missunderstood your first answer i think :) Thanks once again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.