• Guys I have this problem..

    I create an extra stylesheet for my custom gallery shortcode in WordPress.
    I don’t want those styles to load on every single page even when the gallery shortcode isn’t getting used.

    Those are my default scripts and styles for the theme.

    function mytheme_scripts() {
    
    	wp_enqueue_style( 'mytheme-styles', get_stylesheet_uri() );
    	wp_register_style( 'mytheme-gallery-styles', get_template_directory_uri() . '/assets/css/gallery.min.css', array( 'mytheme-gallery' ), null, 'all' );
    
    	wp_deregister_script( 'jquery' );
    	wp_register_script( 'jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js", false, null, true );
    	// wp_enqueue_script( 'jquery' );
    
    	wp_register_script( 'mytheme-gallery', get_template_directory_uri() . '/assets/js/dv_gallery.min.js', array(), null, true );
    
    }
    add_action( 'wp_enqueue_scripts', 'mytheme_scripts' );

    Somewhere further in functions.php I have my custom gallery filter to change the HTML of the native WordPress gallery shortcode.

    .... WALL OF CODE ... 
    
    	wp_enqueue_script( 'mytheme-gallery' );
    
    	return $output;
    
    }
    add_filter( 'post_gallery', 'mytheme_post_gallery', 10, 2 );

    See, first I wp_register.. the ‘mytheme-gallery’ style and script without wp_enqueue ( which outputs them )

    But the mytheme-gallery-style should get included in the head when methane-gallery script is getting wp_enqueued. The script is nicely getting appended after the body but the styles are not in the head section. ?

Viewing 1 replies (of 1 total)
  • The stylesheet will not be automatically enqueued. so you have to enqueue it manually using wp_enqueue_style('mytheme-gallery-styles');

Viewing 1 replies (of 1 total)

The topic ‘My stylesheet doesn't load in the head section?’ is closed to new replies.