diff --git a/includes/functions.php b/includes/functions.php index 76b674e..0d7a124 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -14,6 +14,7 @@ if ( !defined( 'ABSPATH' ) ) exit; function wplt_get_default_options() { return array( 'enable_css' => 1, - 'reset_settings' => 0 z + 'reset_settings' => 0, + 'shortcode_present' => false ); } \ No newline at end of file diff --git a/includes/scripts.php b/includes/scripts.php index 95575f1..e760cc2 100644 --- a/includes/scripts.php +++ b/includes/scripts.php @@ -8,23 +8,26 @@ if ( !defined( 'ABSPATH' ) ) exit; /** * Register scripts and styles - * - * @param string $page current page - * * @return bool */ -function wplt_enqueue_scripts( $page ) { +function wplt_register_scripts() { + // Register frontend CSS + wp_register_style( 'wplt-css', WPLT_PLUGIN_URL . 'includes/css/wp-liveticker2.css', '', WPLT_VERSION, 'all' ); +} +add_action( 'init', 'wplt_register_scripts' ); + +/** + * Print scripts and styles if shortcode is present. + * @return bool + */ +function wplt_print_scripts() { global $wplt_options; - // Register frontend CSS - wp_register_style( 'wplt-css', WPLT_PLUGIN_URL . 'includes/css/wp-liveticker2.css', '', '1.0', 'all' ); - - // Enqueue frontend CSS if option is enabled - if( $wplt_options['enable_css'] ) { - wp_enqueue_style( 'wplt-css' ); + if( $wplt_options['enable_css'] && $wplt_options['shortcode_present'] ) { + wp_print_styles( 'wplt-css' ); } } -add_action( 'wp_enqueue_scripts', 'wplt_enqueue_scripts' ); +add_action( 'wp_footer', 'wplt_print_scripts' ); /** * Register admin scripts and style diff --git a/includes/shortcodes.php b/includes/shortcodes.php index 121deed..bbdabbd 100644 --- a/includes/shortcodes.php +++ b/includes/shortcodes.php @@ -23,6 +23,8 @@ add_filter( 'wp_ajax_get_new_ticks', array( $this, 'wplt_ajax_get_new_ticks' ) ) function wplt_shortcode_ticker_show( $atts ) { global $wplt_options; + $wplt_options['shortcode_present'] = true; + /*$wplt_ticker_options = array(); extract( @@ -37,7 +39,7 @@ function wplt_shortcode_ticker_show( $atts ) { { if(!$atts[1]) $atts[1] = -1; - $output .= '