Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
How to add shortcode in wordpress using Javascript?

I want to put a shortcode in a WordPress website using JavaScript.

Website structure is

<div class="shop-container">
    <div class="wrap">[shortcode here]</div>
    <div class="wc-pr"> </div>
</div>

Firstly, i put div element to above wc-pr using below code.

<script>
    const parent5 = document.querySelector('.shop-container');
    const billingField1 = document.querySelector('.wc-pr');

    const newDiv = document.createElement('div');
    newDiv.setAttribute('id', 'wrap');

    parent5.insertBefore(newDiv, billingField1);
</script>

Then i tried below code.

newDiv.innerHTML = `<?php do_shortcode("[shortcode here]");?>`;
newDiv.innerText = `<?php do_shortcode("[shortcode here]");?>`;

But not working. innertext is diplayed as raw, Hhtml is not showing.

Please let me know how do i solve this

Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are creating/generating an HTML, so you must echo it to the script. So just adding echo to the PHP

newDiv.innerHTML = '<?php echo do_shortcode("[shortcode here]");?>';

instead of

newDiv.innerHTML = '<?php do_shortcode("[shortcode here]");?>';

should do it.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!