Add/Remove “LC Templates”
Introduction
Not to be confused with “post templates” functionality, these are the templates available in editor mode (check screenshot below).
The filter that can be used to alter the available templates is dslc_get_templates and is located in includes/functions.php.
Adding Templates
Here’s an example code for adding your own templates:
function lc_add_new_templates( $templates ) { // Add new templates ( repeat for more templates ) $templates['my-template-id'] = array( 'title' => 'Template Title', 'id' => 'my-template-id', 'code' => 'LIVE COMPOSER CODE', 'section' => 'my templates' ); // Pass them back to LC return $templates; } add_filter( 'dslc_get_templates', 'lc_add_new_templates' );
Things to note:
- The array key and the “id” parameter need to be the same
- Everyone can add/remove templates, so prefix the ID (array key and the “id” parameter) to avoid conflicts
- The “code” parameter holds the Live Composer generated code, you can either get it from “dslc_code” custom field or use the “Export” in the editor
- You can use whatever you like for “section”, just keep in mind “original” is used by the default LC templates and “user” is used for the templates that the users saves from the editor
Removing Default Templates
In case you’d want to remove the default/original templates that come with Live Composer you can do so with this code.
function lc_remove_default_templates( $templates ) { // Go through templates and remove default/original if ( is_array( $templates ) ) { foreach ( $templates as $id => $template ) { if ( $template['section'] == 'original' ) { unset( $templates[$id] ); } } } // Pass them back to LC return $templates; } add_filter( 'dslc_get_templates', 'lc_remove_default_templates' );