dsndm82062
2015-04-13 13:04
浏览 237
已采纳

在wordpress中添加短代码到自定义php文件

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.

图片转代码服务由CSDN问答提供 功能建议

我在php文件中显示以下内容

  &lt; p&gt;&lt;?php echo $ item-&gt; post_content;  ?&gt;&lt; / p&gt; 
   
 
 

当我在wordpress的管理面板中添加新闻项并使用短代码时,问题是显示短代码本身 而不是内容。 是否有任何可能的方法允许在PHP文件中执行短代码?

这是我必须为客户端使用的某种新闻插件,因此无法删除或使用另一个 。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 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 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:

    https://codex.wordpress.org/Function_Reference/do_shortcode

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题