首页 > 解决方案 > 如何将简码插入现有的 html 元素(wordpress)?

问题描述

我需要在[ajaxdomainchecker]现有的 html 代码中插入一个简码。

我尝试了以下代码,但它显示错误。请告诉我如何添加短代码?

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>

标签: phphtmljquerywordpress

解决方案


您可以在帖子中添加短代码,在 ACF 输入中输入数据。并将您的简码设置为该字段的默认值。“进行搜索并输入信息”标签作为另一个 ACF 字段,可帮助您随时更改标签的文本。


推荐阅读