簡體   English   中英

WP簡碼將簡碼輸出為文本

[英]WP shortcode outputs shortcode as text

我正在嘗試在帖子中使用簡碼來顯示畫廊,但在網站上卻將簡碼本身作為文本顯示出來。

我正在使用

<?php the_content();?>

在php文件中。

相同的簡碼可與

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

但是在這種情況下,我需要在帖子編輯器中將其設置為簡碼。

無需編寫PHP代碼,只需將[shortcode here]放在WordPress Post Editor中。

如果要在wordpress帖子編輯器中使用短代碼,則無需編寫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' );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM