Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #237729

    I asked this question for the Eunoia theme, but Replete seems the load order seems to be in the functions.php file.

    I have a child theme set with Replete. However, styles.css file is loading before layout.css and others so I need to make my styles !important to override the next styles.

    Is there a way to modify the functions.php file in the child theme to change the load order?

    #237953

    Hi kork!

    Try putting this on your child theme functions.php:

    	function avia_register_frontend_scripts()
    	{
    		//register js
    		wp_register_script( 'avia-default', AVIA_BASE_URL.'js/avia.js', array('jquery'), 4, false );
    		wp_register_script( 'avia-prettyPhoto',  AVIA_BASE_URL.'js/prettyPhoto/js/jquery.prettyPhoto.js', 'jquery', "3.0.1", true);
    		wp_register_script( 'aviapoly-slider',  AVIA_BASE_URL.'js/aviapoly2.js', 'jquery', "1.0.0", true);
    
    		wp_enqueue_script( 'jquery' );
    		wp_enqueue_script( 'avia-default' );
    		wp_enqueue_script( 'avia-prettyPhoto' );
    		wp_enqueue_script( 'aviapoly-slider' );
    
    		if ( is_singular() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); }
    
    		//register styles
    		wp_register_style( 'avia-style', get_stylesheet_directory_uri()."/style.css", array(), '1', 'all' );
    		wp_register_style( 'avia-grid' , get_template_directory_uri()."/css/grid.css", array(), '1', 'screen' );
    		wp_register_style( 'avia-base' , get_template_directory_uri()."/css/base.css", array(), '1', 'screen' );
    		wp_register_style( 'avia-layout',get_template_directory_uri()."/css/layout.css", array(), '1', 'screen' );
    		wp_register_style( 'avia-scs',   get_template_directory_uri()."/css/shortcodes.css", array(), '1', 'screen' );
    		wp_register_style( 'avia-slide', get_template_directory_uri()."/css/slideshow.css", array(), '1', 'screen' );
    		wp_register_style( 'avia-pf',    get_template_directory_uri()."/js/prettyPhoto/css/prettyPhoto.css", array(), '1', 'screen' );
    		wp_register_style( 'avia-custom',get_template_directory_uri()."/css/custom.css", array(), '1', 'screen' );
    
    		//register styles
    		wp_enqueue_style( 'avia-style');
    		wp_enqueue_style( 'avia-grid');
    		wp_enqueue_style( 'avia-base');
    		wp_enqueue_style( 'avia-layout');
    		wp_enqueue_style( 'avia-scs');
    		wp_enqueue_style( 'avia-slide');
    		wp_enqueue_style( 'avia-pf');
    
    		global $avia;
            $safe_name = avia_backend_safe_string($avia->base_data['prefix']);
            if( get_option('avia_stylesheet_exists'.$safe_name) == 'true' )
            {
                $avia_upload_dir = wp_upload_dir();
    
                $avia_dyn_stylesheet_url = $avia_upload_dir['baseurl'] . '/dynamic_avia/'.$safe_name.'.css';
                wp_register_style( 'avia-dynamic', $avia_dyn_stylesheet_url, array(), '1', 'screen' );
                wp_enqueue_style( 'avia-dynamic');
            }
    
            wp_enqueue_style( 'avia-custom');
    	}

    Change as needed.

    Cheers!
    Josue

    #238139

    I tried that before as well, but receive the error:

    Fatal error: Cannot redeclare avia_register_frontend_scripts() (previously declared in /home/www/public_html/wp-content/themes/child/functions.php:22) in /home/www/public_html/wp-content/themes/child/functions.php on line 138

    #238235

    Hey!

    Please use this instead:

    if(!is_admin())
    {
    	add_action('wp_enqueue_scripts', 'avia_register_frontend_scripts');
    }
    
    function avia_register_frontend_scripts()
    {
    	$template_url = get_template_directory_uri();
    	$child_theme_url = get_stylesheet_directory_uri();
    
    	if ( is_singular() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); }
    
    	//register styles
    	wp_register_style( 'avia-style' ,  $child_theme_url."/style.css", array(), '1', 'screen' ); //register default style.css file. only include in childthemes. has no purpose in main theme
    	wp_register_style( 'avia-grid' ,   $template_url."/css/grid.css", array(), '1', 'screen' );
    	wp_register_style( 'avia-base' ,   $template_url."/css/base.css", array(), '1', 'screen' );
    	wp_register_style( 'avia-layout',  $template_url."/css/layout.css", array(), '1', 'screen' );
    	wp_register_style( 'avia-scs',     $template_url."/css/shortcodes.css", array(), '1', 'screen' );
    	wp_register_style( 'avia-custom',  $template_url."/css/custom.css", array(), '1', 'screen' );
    	wp_register_style( 'avia-prettyP', $template_url."/js/prettyPhoto/css/prettyPhoto.css", array(), '1', 'screen' );
    	wp_register_style( 'avia-media'  , $template_url."/js/mediaelement/skin-1/mediaelementplayer.css", array(), '1', 'screen' );
    
    	//register styles
    
    	wp_enqueue_style( 'avia-grid');
    	wp_enqueue_style( 'avia-base');
    	wp_enqueue_style( 'avia-layout');
    	wp_enqueue_style( 'avia-scs');
    	wp_enqueue_style( 'avia-prettyP');
    	wp_enqueue_style( 'avia-media');
    	
    	        global $avia;
    		$safe_name = avia_backend_safe_string($avia->base_data['prefix']);
    
            if( get_option('avia_stylesheet_exists'.$safe_name) == 'true' )
            {
                $avia_upload_dir = wp_upload_dir();
    
                $avia_dyn_stylesheet_url = $avia_upload_dir['baseurl'] . '/dynamic_avia/'.$safe_name.'.css';
                wp_register_style( 'avia-dynamic', $avia_dyn_stylesheet_url, array(), '1', 'screen' );
                wp_enqueue_style( 'avia-dynamic');
            }
    
    		wp_enqueue_style( 'avia-custom');
    
    		if($child_theme_url !=  $template_url)
    		{
    			wp_enqueue_style( 'avia-style');
    		}
    }
    

    You can play around the order of the wp_enqueue_style:

    wp_enqueue_style( 'avia-grid');
    	wp_enqueue_style( 'avia-base');
    	wp_enqueue_style( 'avia-layout');
    	wp_enqueue_style( 'avia-scs');
    	wp_enqueue_style( 'avia-prettyP');
    	wp_enqueue_style( 'avia-media');

    Note: This might break the layout of the website.

    Best regards,
    Ismael

    #238308

    I still receive the same error…

    Fatal error: Cannot redeclare avia_register_frontend_scripts() (previously declared in /home/www/public_html/wp-content/themes/child/functions.php:27) in /home/www/public_html/wp-content/themes/theme/functions.php on line 138

    • This reply was modified 6 months, 1 week ago by  kork.
    #239176

    Hi!

    In the parent theme change the order in the function the others have referenced above. So lines 163-170:

    
    		//register styles
    		wp_enqueue_style( 'avia-style');
    		wp_enqueue_style( 'avia-grid');
    		wp_enqueue_style( 'avia-base');
    		wp_enqueue_style( 'avia-layout');
    		wp_enqueue_style( 'avia-scs');
    		wp_enqueue_style( 'avia-slide');
    		wp_enqueue_style( 'avia-pf');
    

    Move wp_enqueue_style(‘avia-style’) to the end and it will then get output in the header at the end of the others. We didn’t used to push child themes as much as we do now so its something I should change on all of the previous themes as well.

    Best regards,
    Devin

    #240227

    Ahhh, that’s the challenge. I don’t want to change anything in the parent theme except the custom.css file.

    Child themes are very important to me as I’ve gone through what appears to be the Propulsion UTF-7 hack. Updating the theme also lost all of the custom code I had written. That was a couple years ago so much has changed, but child themes makes it much easier for me to separate my code vs. the theme code.

    I would <thumbs up> changing it on the other themes also. I’ve used nearly all the Themes here (and love them) and have my clients purchase them directly now, but need an easy way to integrate custom code.

    #240343

    I’ve already changed this on the parent so you can either do it too or wait for the update (which could be a while to come out). Its a bug and not something you need to worry about changing in your child theme or anything like that.

    So change that in the parent theme and when the next update comes out it will not need to be re-done.

    #240421

    Awesome Devin! Thanks!

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Load order of CSS files?’ is closed to new replies.