Tagged: child, child theme
- This topic has 5 replies, 2 voices, and was last updated 4 years, 11 months ago by
Theme Horse Support Team.
-
AuthorPosts
-
March 12, 2020 at 5:35 am #75654
sjoerd
ParticipantHello ThemeHorse,
I would like to alter a couple of things so I need to create a child theme – I created for my current site a child-theme too so I’m familiar with it, but somehow I seems to be missing something creating one for newscard pro.
According to the WordPress codex I should enqueue the parent stylesheet but when I do that the site looks terrible
Here is part of my functions.phpadd_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' ); function enqueue_parent_styles() { $parent_style = 'newscard-style'; wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'newscard-child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version') ); }
Here is my styles.css
/* Theme Name: NewsCard Pro Child Theme URI: https://ThemeHorse.com Description: Child theme for NewsCard Pro. Author: sjoerd at boxer.gs Author URI: http://k1600gt.nl/ Template: newscard-pro Version: 1.0 */ .wpgpxmaps, .rl-gallery-link img, .wp-caption img { background-color: #eee; border: 1px solid #ccc; padding: 4px; }
I can activate the child theme perfectly and the two style.css files are in the html output:
link rel='stylesheet' id='newscard-style-css' href='http://10.0.1.101/wp-content/themes/newscard-pro/style.css?ver=5.3.2' type='text/css' media='all' link rel='stylesheet' id='newscard-child-style-css' href='http://10.0.1.101/wp-content/themes/newscard-pro-child/style.css?ver=1.0' type='text/css' media='all'
If I use the old methode using @import then is works but wordpress does not advice it
Please advice or provide me (us) a working set.
Regards,
SjoerdMarch 19, 2020 at 11:57 am #75988Theme Horse Support Team
KeymasterHi Sjoerd,
You have to maintain all of the parent theme dependencies as this theme have more than 1 CSS file. So you need to load Bootstrap CSS before parent theme style.css and then child theme style.css. Please use below code an let us know.
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' ); function enqueue_parent_styles() { $parent_style = 'newscard-style'; wp_enqueue_style( 'bootstrap-style', get_template_directory_uri().'/assets/library/bootstrap/css/bootstrap.min.css', array(), '4.0.0'); wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'newscard-child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version') ); }
Thank you!
March 22, 2020 at 12:12 pm #76049sjoerd
ParticipantExcellent!
I was not aware I had to enqueue bootstrap as well.
Regards
SjoerdMarch 22, 2020 at 4:07 pm #76078Theme Horse Support Team
KeymasterHell Sjoerd,
Bootstrap should load before style.css so you need to enqueue it again in child theme to load it first.
Thank you!
March 22, 2020 at 7:14 pm #76081sjoerd
ParticipantYes,
It’s working now.
Thanks
SjoerdMarch 24, 2020 at 7:40 am #76107Theme Horse Support Team
KeymasterWelcome anytime Sjoerd.
-
AuthorPosts
- You must be logged in to reply to this topic.