Integrating LayerSlider into a theme
Your theme can install LayerSlider as a plugin, from a ZIP inside the theme or on your own server, and deliver its updates. Customers can use their own license.
On this page
To bundle LayerSlider, you need a license for your theme and the theme registered with us, as the rules for bundling LayerSlider describe. You also need the plugin’s installable ZIP from the Downloads page of your LayerSlider account.
Installing LayerSlider with your theme
To install LayerSlider as a plugin with your theme, use the TGM Plugin Activation library. Put the ZIP into your theme, for example in a plugins folder, and add this entry to the list of plugins that your theme passes to the library:
[
'name' => 'LayerSlider',
'slug' => 'LayerSlider',
'source' => get_template_directory() . '/plugins/layerslider.zip',
'version' => '9.0.0',
],Change source to the path of the ZIP in your theme, and version to the version of that ZIP. Keep slug as LayerSlider, with its capitals: it’s the name of the folder inside the ZIP.
How to add the library to a theme, and what the entry’s other keys do, is in the library’s repository.
Don’t use the copy offered for download right after your purchase. That copy has your license built in, so it would try to register your license on your customers’ sites.
Installing LayerSlider from your own server
Instead of shipping the ZIP inside your theme, you can keep it on your own server, behind a protected download. In the entry, give the download’s address as source:
[
'name' => 'LayerSlider',
'slug' => 'LayerSlider',
'source' => 'https://example.com/downloads/layerslider.zip?key=' . $purchase_key,
'version' => '9.0.0',
],Here, $purchase_key holds your customer’s purchase key, which your server checks before it sends the ZIP. TGM Plugin Activation downloads LayerSlider from that address when your customers install or update it.
Protect the download so that only your customers can get the ZIP. Installing LayerSlider from your own server is allowed only with such protection.
How updates reach your customers
Customers without a license of their own get LayerSlider’s updates from you. To ship a newer LayerSlider, download its ZIP from the Downloads page of your LayerSlider account. Put it in the place of the old one, in your theme or on your server. Raise version in the entry to the version of the new ZIP, and release an update of your theme. After your customers update the theme, TGM Plugin Activation offers them the newer LayerSlider.
Customers with a license of their own
A customer who wants the premium templates and features can register a license of their own, and it works with the copy installed with your theme. The updates then come from us. If your customers have questions about the copy that came with your theme, you can send them to the article written for them.
Marking LayerSlider as part of your theme
To mark LayerSlider as part of your theme, call layerslider_set_as_theme() in your theme’s functions.php:
if ( function_exists( 'layerslider_set_as_theme' ) ) {
layerslider_set_as_theme();
}The license box then ends with “Got LayerSlider with a theme? Learn more”, and the link opens a window with a section for customers who got LayerSlider with a theme. The function doesn’t turn off LayerSlider’s update checks or its license notice.
If your theme loads LayerSlider from its own folder
We don’t recommend loading LayerSlider from your theme’s folder, because it can get in the way of updates. Install it with TGM Plugin Activation instead, as above.
A copy that your theme loads from its own folder is updated with your theme. To bring your customers a newer LayerSlider, put the new copy into an update of your theme.
When a customer installs LayerSlider as a plugin and activates it, that copy runs and yours doesn’t start. LayerSlider then shows a notice that several copies are loaded, which asks the customer to turn off your theme’s copy in the theme’s settings, or to contact you.
To let the customer’s copy run without that notice, load your copy only when no other copy of LayerSlider is running. You can also offer an option in your theme’s settings that turns your copy off. Load your copy directly in your theme’s functions.php: a copy loaded from a later hook, such as init, stops your site’s pages and the WordPress admin with a fatal error.
The layerslider_root_url filter gives LayerSlider the address of your copy’s folder. Without it, LayerSlider’s scripts and styles don’t load, on your site or in the WordPress admin. This code adds the filter and loads your copy, both only when no other copy of LayerSlider is running:
if ( ! defined( 'LS_PLUGIN_VERSION' ) ) {
add_filter( 'layerslider_root_url', function () {
return get_template_directory_uri() . '/layerslider';
} );
require_once get_template_directory() . '/layerslider/layerslider.php';
}Change /layerslider in both lines to the folder that holds your copy. Keep the filter inside the condition: outside it, the filter would make a copy that the customer installs as a plugin load its files from your theme’s folder. What the filter receives and returns is in LayerSlider’s actions and filters.