Add Custom JavaScript is a WordPress ability from The Plus Addons for Elementor — usable via Easy MCP AI, which connects Claude, ChatGPT, and any AI assistant to your site.

Install Free Plugin →

Add Custom JavaScript

Write

Adds a custom JavaScript snippet to a page by inserting an HTML widget containing a <script> tag; works with free Elementor.

Requires the The Plus Addons for Elementor plugin (which registers under the 'tpae' ability category) on WordPress 6.9+, with Elementor active. Every ability requires the current user to have the 'edit_posts' capability (and 'edit_post' for the specific post being modified); abilities that create or edit content also verify Elementor and, where relevant, the target The Plus widget are available. A subset of abilities (theme templates, template conditions, dynamic tags, popups, and some custom-code abilities) only register when Elementor Pro is active, and many widget abilities load only in the free plugin when the Pro add-on is inactive.

What it does

Strips any existing <script> tags the caller included, optionally wraps the code in a DOMContentLoaded listener if wrap_dom_ready is true, then wraps the final code in <script> tags to build the HTML widget content. Loads the page's element data, creates an 'html' widget with that content via the element factory, inserts it into the given parent container at the given position via insert_element, and saves the page.

See it in action

You ask your AI assistant

"Insert a custom JS snippet into container abc on page 42 that logs 'loaded' to the console, wrapped in DOMContentLoaded."

Inputs

Name Type Required Description
post_id integer Yes The post/page ID.
parent_id string Yes Parent container element ID.
js string Yes JavaScript code to inject. Do NOT include <script> tags — they are added automatically.
position integer No Insert position within parent. -1 = append (default).
wrap_dom_ready boolean No Wrap the code in a DOMContentLoaded listener. Default: false.

Returns

Returns the new element_id of the inserted HTML widget and the post_id.

Permission

check_raw_code_permission requires the unfiltered_html capability plus edit_posts (and edit_post on post_id if provided), since raw script markup is persisted into post content.

Newsletter

The AI + WordPress space moves fast. Keep up.

New tools, workflow ideas, and product updates — be the first to know what's next.

No spam, unsubscribe anytime.