wp_enqueue_style add to head
-
Hello i am currently using wp_enqueue_style inside my template files and i would like my styles to be inside the <head>
in my functions.php i am registering the style sheets and in my template i am using wp_enqueue_style(‘name’);
Somehow the styles get added to the footer instead of the <head>
-
Try registering and enqueueing in your theme’s functions.php using this method: http://codex.ww.wp.xz.cn/Function_Reference/wp_enqueue_style#Loading_stylesheets_in_WordPress_themes
Thats what i am doing, register in the functions.php
call enqueue in the template itself.
Have you tried regestering and enqueueing from inside the action call “wp_enqueue_scripts” inside your theme’s functions.php as in the example?
I could do that, but i want to load in specific styles on each template.
How will i do this from within the functions.php?
Use conditional tags to enqueue only on the pages you want: http://codex.ww.wp.xz.cn/Conditional_Tags
Or if your stylesheet doesn’t depend on other stylesheets you could also just use this inside the
<head></head>tags:<link rel="stylesheet" type="text/css" media="all" href="<?php echo get_template_directory_uri() . "/custom-style.css"; ?>" />Change “custom-style.css” for the stylesheet name you want to show.
Thanks, using conditional tags now.
I’m having a similar problem. I’m trying to add styles and scripts to my plugin so I use:
function add_my_scripts() { wp_register_script( 'test_scripts', plugins_url('test_scripts.js', __FILE__) ); wp_enqueue_script( 'test_scripts' ); } add_my_scripts();in my plugin page but it adds the script to the footer rather than inside the <head> tags. The same thing happens with wp_enqueue_style.
I’d like a solution to this too – I’ve read elsewhere that it adds in the footer rather than the head, and that’s my personal experience.
My angle is that I want to add a custom stylesheet (for use in a child theme) after an internal stylesheet i.e further down the page. Using wp_head() would output the link above the internal stylesheet.
Moving wp_head() isn’t an option
Just found this:
http://codex.ww.wp.xz.cn/Function_Reference/wp_enqueue_style
As of WordPress 3.3 wp_enqueue_style() can be called mid-page (in the HTML body). This will load styles in the footer.Still looking
Think it’s a bug – enqueue_scripts has the option to load in the footer, probably very similar code and someone overlooked. Why would anyone want to load styles in the footer? (see above) Does the codex mean scripts?
The topic ‘wp_enqueue_style add to head’ is closed to new replies.