我正试图在帖子中使用短代码来显示图库,但在网站上它将短代码本身作为文本输出。 我正在使用
<?php the_content();?>
在PHP文件中。 相同的短码适用于
<?php echo do_shortcode('[shortcode here]')?>
但在这种情况下,我需要在帖子编辑器中将其作为短代码。
无需编写PHP代码,只需将[shortcode here]
放入WordPress Post Editor即可。
如果你想在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
尝试在活动主题functions.php中添加以下代码
add_filter( 'the_content', 'do_shortcode' );