WordPress.org

Forums

The Bootstrap
Replacing CSS in Child Theme (3 posts)

  1. niallolaoghaire
    Member
    Posted 1 year ago #

    Hi
    The Bootstrap uses two CSS files (css/bootstrap[min].css & style.css) I wanted to change both so I used this code in the functions.php in the child theme (Thermory):

    function remove_thematic_actions() {
        remove_action( 'init', 'the_bootstrap_register_scripts_styles' );
    }
    add_action('init','remove_thematic_actions');
    
    function thermory_register_scripts_styles() {
    	if ( ! is_admin() ) {
    		$theme_version = _the_bootstrap_version();
    		$suffix = ( defined('SCRIPT_DEBUG') AND SCRIPT_DEBUG ) ? '' : '.min';
    
    		/**
    		 * Scripts
    		 */
    		wp_register_script(
    			'tw-bootstrap',
    			get_template_directory_uri() . "/js/bootstrap{$suffix}.js",
    			array('jquery'),
    			'2.0.3',
    			true
    		);
    
    		wp_register_script(
    			'the-bootstrap',
    			get_template_directory_uri() . "/js/the-bootstrap{$suffix}.js",
    			array('tw-bootstrap'),
    			$theme_version,
    			true
    		);
    
    		/**
    		 * Styles
    		 */
    		wp_register_style(
    			'tw-bootstrap',
    			get_stylesheet_directory_uri() . "/css/bootstrap.css",
    			array(),
    			'2.0.3'
    		);
    
    		wp_register_style(
    			'the-bootstrap',
    			get_stylesheet_directory_uri() . "/style.css",
    			array('tw-bootstrap'),
    			$theme_version
    		);
    	}
    }
    add_action( 'init', 'thermory_register_scripts_styles' );

    which (when I view page source) has created links to the new css in my child theme, however the css is still linking back to The Bootstrap parent theme despite the fact that: a) there is no link to it b) even when I delete the original code from the parent functions.php file it still links. The only way to stop it is by renaming the parent's theme css file (bootstrap.min.css) then it links to the child theme css. I'd rather find out what I'm doing wrong than use this stop gap solution.
    Thanks

  2. duncanmoo
    Member
    Posted 1 year ago #

    You have probably figured this out, but get_template_directory_uri() will return the parent theme's directory.

    Use get_stylesheet_directory_uri() to include resources that are intended to be included in/over-ridden by the Child Theme.

  3. niallolaoghaire
    Member
    Posted 1 year ago #

    Hi
    Sorry to take so long to get back & thanks for your reply duncanmoo, doing another site with the-bootstrap theme & got the same issue! I thought I was already using get_stylesheet_directory_uri() in the above code, am I missing something?

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic

Tags

No tags yet.