簡體   English   中英

與jQuery的WordPress do_shortcode不起作用

[英]Wordpress do_shortcode with jquery not working

這是代碼

jQuery('#home_page_banner').html('<?php echo do_shortcode("[banner id="6135"]"); ?>');

結果:

輸入圖像描述

試試下面的代碼為簡碼

$('#home_page_banner').html(<?php echo do_shortcode('[banner id="6135"]'); ?>);

要么

jQuery('#home_page_banner').html(<?php echo do_shortcode('[banner id="6135"]'); ?>);

不能完全確定為什么要這樣做,因為使用其他代碼創建其他代碼是非常糟糕的做法。 您可以將簡碼直接包含在頁面模板中,然后如果不希望在所有頁面上都顯示,則僅使用條件標簽。

根據您擁有的div ID,is_front_page()將為您解決問題。 如果出於某種原因要使用jQuery創建,則可以簽出WP Rest API。

WP條件標簽

此完整代碼。 `function jsUpdateSize(){var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; if(width <= 450){jQuery('#home_page_banner')。html(''); jQuery的( '#banner_a1')的html( '')。 }其他if(width <= 850){jQuery('#home_page_banner')。html(''); jQuery的( '#banner_a1')的html( '')。 }其他{
jQuery的( '#home_page_banner')的html( '')。 jQuery的( '#banner_a1')的html( '')。 }
}

window.onload = jsUpdateSize;
window.onresize = jsUpdateSize;`

暫無
暫無

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

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