1

I would like to insert and execute some WordPress shortcode through main.js file, in a string "", but the problem is that it won't execute!

Here is an example of my main.js:

..
},
"March 6": {
    "title": "6 March",
    "subtitle": "Sample text",
    "content": "[sc name=\"sampleshortcode\"]"
},
..

So with this, I see only [sc name="sampleshortcode"] as executed on my WordPress page.

Looking to find the solution to show WordPress shortcode through "string". Or any other idea.

2

2 Answers 2

1

This answer shows the process of executing a shortcode with JavaScript. You may have to do a derivative of this in order to successfully do what you are trying to do, but the methodology is inscribed within will inform your actions more thoroughly.

0

If you're just looking for a way to get some data from database for the javascript, then you could consider using admin-ajax, WP REST API or even wp_localize_script to get and make available the data you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.