How do I make the plugin only execute when it is used?
-
I developed a plugin to play self-hosted asciinema videos. The plugin adds the CSS and JavaScript files required for the player to run on each page, regardless of whether the plugin is used or not.
How do I make the plugin to detect when to add the style and CSS files required for the player to work. The video is inserted using the following tag: <asciinema-player src=”asciicast.json”></asciinema-player>. Can I check for that tag in the post and if it’s used don’t add the CSS and JavaScript files?
I’ll show you the code I used because it’s very short, and you can better understand me. Here it is:
defined('ABSPATH') or die('No script kiddies please!'); function enqueue_scripts() { if (!is_admin()) { wp_register_script('asciinema-player-js', plugins_url('asciinema-player.js', __FILE__), array(), $ver = '2.4.0', true); wp_register_style('asciinema-player-css', plugins_url('asciinema-player.css', __FILE__), array(), $ver = '2.4.0'); wp_enqueue_script('asciinema-player-js'); wp_enqueue_style('asciinema-player-css'); } } function execute() { add_action('wp_enqueue_scripts', 'enqueue_scripts'); } execute();
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How do I make the plugin only execute when it is used?’ is closed to new replies.