- 1. Why Enqueuing Matters
- 2. Enqueueing Custom JS in a Child Theme
- 3. Enqueueing Custom JS in a Custom Plugin
- 4. Target Only Pages Where Terminal Is Present (Optional)
- 5. Enqueueing Admin-Specific Scripts (For Add-On Settings Panels)
- 6. Enqueue CSS for Custom Output Types (Optional)
- 7. Using ES Modules (Advanced)
- 8. Handling Dependencies Correctly
- 9. Where to Put Your Files
- 10. Summary
To extend the Cointacted Social Terminal with your own commands, event listeners, or add-on logic, you need to load your custom JavaScript after the terminal’s core scripts.
This article explains exactly how to enqueue custom JS files in a safe, compatible way.
1. Why Enqueuing Matters #
The terminal initializes in its main script:
cointacted-social-terminal-js
Your custom command code must load after it, otherwise:
- the registry won’t exist yet
- events won’t fire
- your commands won’t register
Correct enqueueing ensures:
✔ registry is available #
✔ terminal is initialized #
✔ commands register successfully #
✔ add-ons behave correctly #
2. Enqueueing Custom JS in a Child Theme #
Add this to your child theme’s functions.php:
function my_terminal_extension_scripts() {
wp_enqueue_script(
'my-terminal-ext',
get_stylesheet_directory_uri() . '/terminal-ext.js',
['cointacted-social-terminal-js'], // load AFTER core terminal JS
'1.0',
true
);
}
add_action('wp_enqueue_scripts', 'my_terminal_extension_scripts');
Your terminal-ext.js may contain:
CointactedSocialTerminalTerminal.registry.test = function() {
cointacted_social_terminal_append_line("Custom command loaded!", "success");
};
Usage:
test
3. Enqueueing Custom JS in a Custom Plugin #
This is the preferred method for:
- company projects
- advanced extensions
- reusable modules
- Cointacted add-ons
Create a plugin file:
<?php
/*
Plugin Name: My Terminal Extension
*/
add_action('wp_enqueue_scripts', function () {
wp_enqueue_script(
'my-ext',
plugin_dir_url(__FILE__) . 'addon.js',
['cointacted-social-terminal-js'],
'1.0',
true
);
});
4. Target Only Pages Where Terminal Is Present (Optional) #
To avoid loading your commands on the whole site:
if (has_shortcode($post->post_content, 'cointacted_social_terminal')) {
wp_enqueue_script(...);
}
Or target a specific page ID:
if (is_page(42)) {
wp_enqueue_script(...);
}
5. Enqueueing Admin-Specific Scripts (For Add-On Settings Panels) #
If your add-on has admin UI:
add_action('admin_enqueue_scripts', function() {
wp_enqueue_script(
'my-admin-ext',
plugin_dir_url(__FILE__) . 'admin.js',
['jquery'],
'1.0',
true
);
});
This is separate from terminal logic and handles:
- settings pages
- admin UI features
- backend AJAX logic
6. Enqueue CSS for Custom Output Types (Optional) #
If your custom command uses a new output type:
.cointacted-social-terminal__line--reward {
color: #00cc66;
font-weight: bold;
}
Enqueue the CSS:
wp_enqueue_style(
'my-terminal-css',
plugin_dir_url(__FILE__) . 'addon.css',
[],
'1.0'
);
Then output with your new type:
cointacted_social_terminal_append_line("+15 XP", "reward");
7. Using ES Modules (Advanced) #
Because your terminal uses a namespaced global object, ES modules must wrap or re-export the registry.
But you can still use:
wp_enqueue_script(
'my-module',
plugin_dir_url(__FILE__) . 'module.js',
['cointacted-social-terminal-js'],
'1.0',
true
);
Just avoid using import unless bundling, because WordPress will treat module scripts differently.
8. Handling Dependencies Correctly #
Always include:
['cointacted-social-terminal-js']
as a dependency.
This guarantees:
✔ registry is ready #
✔ terminal is initialized #
✔ helper functions exist #
✔ settings state is available #
Without this, your commands may fail or not register.
9. Where to Put Your Files #
Recommended structure for scalable development:
my-addon/
│ addon.php
│ readme.txt
│
├─ js/
│ addon.js
│
└─ css/
addon.css
For child themes:
yourtheme-child/
│ functions.php
│
└─ terminal-ext.js
10. Summary #
Enqueuing custom scripts properly ensures your commands:
✔ register correctly #
✔ load after core terminal scripts #
✔ can access registry, events, and helpers #
✔ integrate cleanly as add-ons #
✔ remain compatible with WordPress upgrades #
This is the foundation of extending the terminal.