2015-04-13 13:04 阅读 119


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条回答 默认 最新

  • 已采纳
    douzhimei8259 douzhimei8259 2015-04-13 13:31

    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.

    点赞 评论 复制链接分享
  • dongzouban9871 dongzouban9871 2015-04-13 13:18

    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:


    点赞 评论 复制链接分享