• thelittlegreenman

    (@thelittlegreenman)


    Hi,

    I created a child theme and it works with the main style.css file but I have a second file in which I need to make changes. This file however is not in the root of the child theme but in css/grid.css.
    How can I now replace the child grid.css with the original one in the theme?
    I’m searching now for hours and tried all kind of tipps

    function my_theme_enqueue_styles() {
    
        $parent_style = 'parent-style'; // 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')
        );
    
    }
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' , PHP_INT_MAX);
    

    That’s the file that I need to replace with the altered child grid.css
    <link rel=’stylesheet’ id=’photography-responsive-css-css’ href=’https://domain.com/wp-content/themes/photography/css/grid.css&#8217; type=’text/css’ media=’all’ />

Viewing 4 replies - 1 through 4 (of 4 total)
  • catacaustic

    (@catacaustic)

    If you want to swap it out for another stylesheet, the easy thing ot do is register your new stylesheet using the same alias after the originalone has been registered.

    With just a few hints from your code, something like this maybe…

    function register_new_grid_css() {
        wp_enqueue_style ('photography-responsive-css', 'my-grid.css');
    }
    
    add_action ('wp_enqueue_scripts', 'register_new_grid_css', 100);

    You’ll need to check the alias used, and the priority that the original file is enqueued at, but that should work.

    Thread Starter thelittlegreenman

    (@thelittlegreenman)

    Obviously that’s the problem as it’s not working

    I found this code in the parents functions

    
    //Enqueue mobile CSS after all others CSS load
    function photography_register_mobile_css() 
    {
    	//Check if enable responsive layout
    	$tg_mobile_responsive = kirki_get_option('tg_mobile_responsive');
    	
    	if(!empty($tg_mobile_responsive))
    	{
    		//enqueue frontend css files
    		$pp_advance_combine_css = get_option('pp_advance_combine_css');
    	
    		if(!empty($pp_advance_combine_css))
    		{
    			wp_enqueue_style("photography-responsive-css", admin_url('admin-ajax.php')."?action=photography_responsive_css", false, "", "all");
    		}
    		else
    		{
    	    	wp_enqueue_style('photography-responsive-css', get_template_directory_uri()."/css/grid.css", false, "", "all");
    	    }
    	}
    }
    add_action('wp_enqueue_scripts', 'photography_register_mobile_css', 15);

    Your code adds an additional file and attends “css” at the end of the original style “photography-responsive-css-css”

    Thread Starter thelittlegreenman

    (@thelittlegreenman)

    Somehow I can’t remove that grid.css at all. I mean the original even if I dont enqueue the new one

    When commenting this
    add_action('wp_enqueue_scripts', 'photography_register_mobile_css', 15); out
    in the parent functions the grid.css-file is missing but all my attemps to remove this action in the child-theme-functions don’t work

    catacaustic

    (@catacaustic)

    So what code have you used to try and remove it? Without seeing that it’s almost impossible to know what cold be wrong.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to override a special css.file in a child theme’ is closed to new replies.