This guide shows theme developers and site builders how to customize JakBot’s chat interface templates using the theme override system. You’ll learn to safely modify templates in your active theme without losing changes during plugin updates.
Understanding the Template Override System
The template override system allows you to copy any chat interface template into your active theme directory. Once a copy exists in your theme, JakBot loads your version instead of its own. This approach ensures plugin updates never overwrite your customizations and enables per-theme template customization with full WordPress child-theme hierarchy support.
Setting Up Template Overrides
Creating the Directory Structure
- Navigate to your active theme directory at
wp-content/themes/your-theme/ - Create a new subdirectory named
jays-chat-assistant - Inside this directory, create a folder named after your template (e.g.,
standard) - Place your template files in this structure:
your-theme/jays-chat-assistant/{template-name}/
your-theme/
jays-chat-assistant/
standard/
chat-interface.php (required)
style.css (optional)
script.js (optional)
template.json (optional)
For child themes, use the same structure in your child theme directory. Child-theme files take priority over parent-theme files, which take priority over plugin files.
Copying Templates via Admin UI
- Go to JakBot > Templates in your WordPress admin dashboard
- Locate the template card you want to customize
- Click the Copy to Theme button
- Verify the plugin copies all template files to your theme directory
- Begin editing the copied files directly in your theme
Ensure your theme directory has write permissions for the web server user, or the Copy to Theme button will be disabled.
Copying Templates Manually
- Locate the source template in
wp-content/plugins/jays-chat-assistant/templates/{template-name}/ - Copy the entire template directory to
wp-content/themes/your-theme/jays-chat-assistant/{template-name}/ - Clear the template cache or wait for automatic detection on the next page load
Understanding Template Files
Required and Optional Files
- Create
chat-interface.phpas your main template file containing HTML output for the chatbot widget - Add
style.cssfor template-specific stylesheets (automatically enqueued with cache-busting) - Include
script.jsfor template-specific JavaScript (automatically enqueued with jQuery dependency) - Configure
template.jsonfor template metadata, version tracking, and feature support flags
Creating Template Metadata
- Create a
template.jsonfile in your template directory - Define the template name, description, version, and author information
- Specify supported features like minimize, transcript, avatar, and positioning options
- Set default settings for the template
{
"name": "My Custom Template",
"description": "A customized chat interface for the Acme theme.",
"version": "1.2.0",
"author": "Your Name",
"min_plugin_version": "2.1.0",
"supports": {
"minimize": true,
"transcript": true,
"avatar": true,
"positioning": ["bottom-right", "bottom-left", "top-right", "top-left"]
},
"settings": {
"default_position": "bottom-right"
}
}
Working with Template Variables
- Access extracted PHP variables in your
chat-interface.phptemplate file - Use
$bot_idfor the database ID of the active bot - Reference
$bot_nameand$bot_slugfor display name and URL-safe slug - Access
$welcome_messagearray for welcome message strings - Use
$userfor the currently logged-in user object - Reference
$position,$minimize, and$style_stringfor widget settings
Always check variables with
isset() before using them, as default values may not be set in all contexts.Customizing Template Behavior with Filters
Modifying Template Directory Location
- Add the
jca_theme_override_dirfilter to your theme’sfunctions.php - Return your preferred directory name instead of the default
jays-chat-assistant
add_filter( 'jca_theme_override_dir', function( $dir ) {
return 'my-chatbot-templates';
} );
Adding Custom Template Search Locations
- Use the
jca_template_search_locationsfilter to add new directories to the search path - Add shared template directories for network/multisite installations
- Specify the template name and file parameters for targeted customizations
add_filter( 'jca_template_search_locations', function( $locations, $template, $file ) {
// Add a network-wide shared directory before the plugin default
array_splice( $locations, -1, 0, array(
'/var/www/shared-templates/' . $template . '/' . $file
) );
return $locations;
}, 10, 3 );
Modifying Template Output
- Apply the
jca_template_render_outputfilter to modify final HTML output - Access the complete HTML string, template name, and data variables
- Return modified HTML output for lightweight customizations
add_filter( 'jca_template_render_output', function( $output, $template, $data ) {
return '' . $output . '';
}, 10, 3 );
Managing Template Versions and Updates
Handling Template Updates
- Monitor the admin UI for templates flagged as Outdated when your theme version is older than the plugin version
- Choose Update (Overwrite) to replace your theme files with current plugin versions (creates timestamped backup)
- Select Safe Update (.new) to write new plugin files alongside yours with
.newsuffix - Review
.newfiles and manually merge changes as needed
Version Control Best Practices
- Increment the
versionfield intemplate.jsonwhenever you make significant changes - Use the
min_plugin_versionfield to document minimum plugin requirements