【发布时间】:2021-09-27 14:38:42
【问题描述】:
我需要在现有的 html 代码中插入一个短代码 [ajaxdomainchecker]。
我尝试了以下代码,但显示错误。请告诉我如何添加短代码?
SyntaxError: Unexpected identifier:
<script>
jQuery(document).ready(function(){
var sessionName = '<?php echo do_shortcode("[ajaxdomainchecker]"); ?>';
jQuery(" .acf-field-60po7a8eu9444 p.description").html(sessionName);
});
</script>
SyntaxError: missing ) after argument list
jQuery(' .acf-field-60po7a8eu9444 p.description').html('<?php echo do_shortcode("[ajaxdomainchecker]"); ?>');
SyntaxError: Invalid or unexpected token
jQuery(" .acf-field-60po7a8eu9444 p.description").html("<?php echo do_shortcode('[ajaxdomainchecker]'); ?>");
SyntaxError: Unexpected token
jQuery('.acf-field-60f5d9a279544 p.description').html(<?php echo do_shortcode('[ajaxdomainchecker]'); ?>);
现有代码(使用acf/frontend创建):
<div class="acf-field acf-field-textarea acf-field-60po7a8eu9444 elementor-repeater-item-b95d154" data-name="rtype_selection_desc" data-type="textarea" data-key="field_60po7a8eu9444">
<div class="acf-label">
<label for="acf-field_60po7a8eu9444">Enter Info</label>
</div>
<div class="acf-input">
<p class="description">Search and Enter Info</p>
<!-- how to add the short code here? -->
<textarea id="acf-field_60po7a8eu9444" name="acf[field_60po7a8eu9444]" rows="8"></textarea>
</div>
</div>
【问题讨论】:
-
isbe,在 php 代码运行后无法有意义地插入短代码。它需要在存储在数据库中的 html 代码中。当 wordpress 为页面内容生成 html 时,它基本上会进行文本替换 - 将 [shortcode] 替换为简码处理函数返回的输出。
-
嗨 anmari:啊,我明白了,谢谢你们的 cmets。我删除了 :after 并再次尝试,但仍然显示相同的错误。请告诉我如何解决这个问题?