SeanFF
SeanFF

Reputation: 19

Additional css file in wordpress not linking through a functions.php file?

I am trying to link my css file to WordPress through a functions.php file. I am not getting any errors but my page isn't showing up styled at all. Am I missing something?

Here is my code:

<?php

function my_own_styles() {

wp_enqueue_style( 'portfolio_theme', get_template_directory_uri() . 
'/css/portfolio.css' );

}

add_action( 'wp_enqueue_scripts', 'my_own_styles()' );

?> 

Upvotes: 0

Views: 61

Answers (2)

FluffyKitten
FluffyKitten

Reputation: 14312

If you are using a child theme - which I assume you are when you're making changes such as adding CSS and changing functions.php - then you need to use get_stylesheet_directory_uri instead of get_template_directory_uri, i.e.

function my_own_styles() {

    wp_enqueue_style( 'portfolio_theme', get_stylesheet_directory_uri() . 
'/css/portfolio.css' );

}

add_action( 'wp_enqueue_scripts', 'my_own_styles' );

get_template_directory_uri() returns the path to the current theme unless a child them is being used. In that case it returns the path to the parent theme.

get_stylesheet_directory_uri returns the path to the current theme even if it is a child theme.

Upvotes: 1

WizardCoder
WizardCoder

Reputation: 3461

When delcaring a function in the add_action function you don't need to use the (), just the name of the function. See how your code should look below.

<?php

function my_own_styles() {

wp_enqueue_style( 'portfolio_theme', get_template_directory_uri() . 
'/css/portfolio.css' );

}

add_action( 'wp_enqueue_scripts', 'my_own_styles' );

?> 

Upvotes: 1

Related Questions