简体   繁体   中英

How to insert a shortcode to an existing html elements (wordpress)?

I need to insert a shortcode [ajaxdomainchecker] into an existing html code.

I tried the following code but it shows error. Would you please let me know how to add the shortcode?

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]'); ?>);

Existing code (created using 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>

您对 do_shortcode() 命令有正确的想法,但您可以像这样将其直接放入 PHP 文件中:

<?php echo do_shortcode("[ajaxdomainchecker]"); ?>

You can add the shortcode in your post where you enter the data in ACF input. And set your shortcode as a default value to that field. "Make a search and enter info" label as another ACF field that helps you change the text of the label whenever you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM