admin_url( 'admin-ajax.php' ), 'nonce_shares' => wp_create_nonce( 'fasto_count_shares' ), )); $data = array( 'url' => FASTO_URI, ); wp_localize_script( 'lazy', 'object_name', $data ); } add_action( 'wp_enqueue_scripts' , 'fasto_load_scripts' , 1 ); /* ================================================================================================================= fasto_gutenberg_gallery_enqueue() - enqueue CSS and JS gallery only if needed ================================================================================================================= */ function fasto_gutenberg_gallery_enqueue(){ if ( is_singular('post') ){ $post = get_post(); //backward compatibility - this function was introduced in Wordpress 5.0.0 if ( function_exists( 'has_blocks' ) ){ if ( has_blocks( $post->post_content ) ) { $blocks = parse_blocks( $post->post_content ); foreach ( $blocks as $block ){ if( $block['blockName'] === 'core/gallery' ){ wp_enqueue_style( 'simple-lightbox' , FASTO_URI.'/css/simple-lightbox.min.css', array(), '1.0', 'all' ); wp_enqueue_script( 'simple-lightbox', FASTO_URI."/js/simple-lightbox.min.js", '', '', true ); } } } } else{ wp_enqueue_style( 'simple-lightbox' , FASTO_URI.'/css/simple-lightbox.min.css', array(), '1.0', 'all' ); wp_enqueue_script( 'simple-lightbox', FASTO_URI."/js/simple-lightbox.min.js", '', '', true ); } } } add_action( 'get_footer','fasto_gutenberg_gallery_enqueue',1 ); /* ================================================================================================================= fasto_widget_gallery_enqueue() - enqueue CSS and JS if widget has gallery ================================================================================================================= */ function fasto_widget_gallery_enqueue(){ $widgets = wp_get_sidebars_widgets(); unset( $widgets['wp_inactive_widgets'] ); foreach ( $widgets as $widget ){ foreach ( $widget as $w ){ if ( stripos ( $w, 'media_gallery' ) !== false ){ wp_enqueue_style( 'simple-lightbox' , FASTO_URI.'/css/simple-lightbox.min.css', array(), '1.0', 'all' ); wp_enqueue_script( 'simple-lightbox', FASTO_URI."/js/simple-lightbox.min.js", '', '', true ); } } } } add_action( 'get_footer','fasto_widget_gallery_enqueue',1 ); /* ================================================================================================================= fasto_load_admin_styles() - enqueue the CSS files in admin ================================================================================================================= */ function fasto_load_admin_styles() { wp_enqueue_style( 'admin-fasto' , FASTO_URI.'/css/admin.css', array(), '1.0', 'all' ); } add_action( 'admin_enqueue_scripts', 'fasto_load_admin_styles' ); /* ================================================================================================================= fasto_load_admin_scripts() - enqueue the JS files in admin for future use - commented action for now ================================================================================================================= */ function fasto_load_admin_scripts() { } //add_action( 'admin_enqueue_scripts', 'fasto_load_admin_scripts' );