Replies: 0
Theme: Teletype
Issue: Child theme loading theme stylesheets BEFORE bootstrap stylesheet
Using the recomended code:
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
$parent_style = 'teletype-css'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
The “parent” stylesheet (and child) jumped from being the 7th or so in the page source to being right before the “bootstrap.min.css” stylesheet (bootstrap.min.cs being the 2nd stylesheet)
After some digging and finding and add_action priority would move it, but caused double loading of the child theme stylesheet, I found wp_register_style() and arrived at the following code.
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
$parent_style = 'teletype-css';
wp_register_style( $parent_style, get_template_directory_uri() . '/style.css', array('bootstrap-css') );
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-css',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
I’ve never used this before, so I am asking “Am I doing this right?” and of course, is this in fact the best way to do this?