• I would like to add a custom CSS File to my OceanWP child theme but for some reason it isn’t loading.

    function prefix_custom_styles() {
    	// Dynamically get version number of the parent stylesheet (lets browsers re-cache your stylesheet when you update your theme)
    	$theme   = wp_get_theme( 'OceanWP' );
    	$version = $theme->get( 'Version' );
    
    	wp_enqueue_style('flags', get_stylesheet_directory_uri() . '/flags/flags.css' );
    
    }
    add_action( 'wp_enqueue_styles', 'prefix_custom_styles' );

    The above doesn’t work, can anyone see why?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Try to use get_template_directory_uri() in your code instead of get_stylesheet_directory_uri() or use the below code.

    function add_theme_css() {
      wp_enqueue_style( 'flags', get_template_directory_uri() . '/flags/flags.css' );
    }
    add_action( 'wp_enqueue_scripts', 'add_theme_css' );
    • This reply was modified 5 years, 8 months ago by Amit Singh.
    Thread Starter conciseac

    (@conciseac)

    Thanks – but that didn’t work for me – but this did (by changing this line):

    get_stylesheet_directory_uri()

    Thanks!

    Glad to hear that it is fixed!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add a CSS file via the child theme’ is closed to new replies.