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
WriteAdds 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.
More The Plus Addons for Elementor abilities
Accordion
Adds The Plus Addons "Accordion" widget (tp-accordion) to an Elementor container.
Add Code Snippet
Creates a site-wide Custom Code snippet using Elementor Pro, injecting CSS/JS/meta into the head or body on all pages.
Add Container
Adds a new Elementor flex container to a page or nests it inside another existing container.
Add Container
Adds a flex or grid container to a page, optionally nested inside a parent container.
Add Custom CSS
Adds custom CSS to a specific element or to the entire page (requires Elementor Pro).
Add Stock Image
Searches Openverse for an image, downloads it to the Media Library, and adds it as an image widget to the page in one step.