在Wordpress中链接样式表

I am trying to link my stylesheet to another page in Wordpress. The actual Wordpress installation is within a folder, within the actual site. It's set up this way because I only want to use WP for a specific section of the site (it was an afterthought, I know this is isn't necessarily the "correct" way to do things...)

I have the front page set up and the styles are all working fine. But when a create a new page and try to use get_header to pull in the styles, they don't work. The browser is looking for a page called styles.css, not a stylesheet.

I've tried to use "enqueue" in the functions.php file, but it still won't work. I have a copy of my style sheet in the theme folder and also one inside a css folder.

Example of using enqueue for the copy inside the css folder:

wp_enqueue_script( 'styles', 'get_stylesheet_directory_uri()' . 'css/styles2.css' );

*I am using get_header in my page template file, (same header as the front page which is working fine), and it is linked this way:

<link rel="stylesheet" type="text/css" href="../css/styles2.css">

I'm pretty sure the issue is the "../" but when I substitute echo get_stylesheet_directory_uri()....... instead of the ../, it doesn't work as it should.

Any help would be great as I'm newer to WP development.

Thanks everyone

You have to write like this for linking template style sheet ...

 wp_enqueue_script( 'styles', get_template_directory_uri(). 'css/styles2.css',  array(), '0.0.1' );

Add Style sheet like this:

wp_enqueue_style( 'styles', bloginfo('template_url').'/css/styles2.css' );

You can view more detail at here

You need to hook the css: If you are using child theme then hook like:

add_action( 'wp_enqueue_scripts', 'enqueue_unique_function_name_here', 0);
function enqueue_unique_function_name_here()
{
    wp_enqueue_style( 'css_unique_handle_name_here', get_template_directory_uri(). 'folder_path_inside_child_theme/style_sheet_file_name_here.css',  array(), '0.0.1' );
}

If you are using parent theme (no child theme) then hook like:

add_action( 'wp_enqueue_scripts', 'enqueue_unique_function_name_here', 0);
function enqueue_unique_function_name_here()
{
    wp_enqueue_style( 'css_unique_handle_name_here', get_stylesheet_directory_uri(). 'folder_path_inside_child_theme/style_sheet_file_name_here.css',  array(), '0.0.1' );
}

If want to enqueue in admin side then just change hook name "wp_enqueue_scripts" to "admin_enqueue_scripts".

Try now.

You have used wp_enqueue_script() instead of wp_enqueue_style()

wp_enqueue_style used for Enqueue Style
wp_enqueue_script used for Enqueue Script

wp_enqueue_style( 'styles', 'get_stylesheet_directory_uri()' . 'css/styles2.css' );

Here is the full example for the same.

add_action( 'wp_enqueue_scripts', 'enqueue_custom_style');
function enqueue_custom_style()
{
    wp_enqueue_style( 'styles', 'get_stylesheet_directory_uri()' . 'css/styles2.css' );
}