WP短代码将短代码输出为文本

问题描述 投票:0回答:3

我正试图在帖子中使用短代码来显示图库,但在网站上它将短代码本身作为文本输出。 我正在使用

<?php the_content();?>

在PHP文件中。 相同的短码适用于

<?php echo do_shortcode('[shortcode here]')?>

但在这种情况下,我需要在帖子编辑器中将其作为短代码。

php wordpress shortcode
3个回答
0
投票

无需编写PHP代码,只需将[shortcode here]放入WordPress Post Editor即可。


0
投票

如果你想在wordpress post编辑器中使用短代码,那么就不需要编写php代码了。

如果你想在任何wordpress .php文件中使用the_content(),那么你需要编写并遵循代码模式。

例如(single.php的例子) -

<?php
  while (have_posts()) : the_post();
  the_title(); 
  the_content();
  endwhile;
?>

让我们考虑一下你在结帐页面,在dashboard > Pages > Checkout Page你输入这个[woocommerce_checkout]和你wordpress的page-checkout.php文件,你可以编写你的自定义代码使它工作。

这是我的自定义代码的示例:

<?php
  if (have_posts()) : while (have_posts()) :
    the_post(); ?>
      <div class="container">
          <div class="checkout-page my-4">
              <?php the_content(); ?>
          </div>
      </div>
<?php endwhile; endif; ?>

抱歉英文不好:-P


0
投票

尝试在活动主题functions.php中添加以下代码

add_filter( 'the_content', 'do_shortcode' );
© www.soinside.com 2019 - 2024. All rights reserved.