WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_enqueue_style add to head (9 posts)

  1. nytrm
    Member
    Posted 1 year ago #

    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>

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Try registering and enqueueing in your theme's functions.php using this method: http://codex.wordpress.org/Function_Reference/wp_enqueue_style#Loading_stylesheets_in_WordPress_themes

  3. nytrm
    Member
    Posted 1 year ago #

    Thats what i am doing, register in the functions.php

    call enqueue in the template itself.

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    Have you tried regestering and enqueueing from inside the action call "wp_enqueue_scripts" inside your theme's functions.php as in the example?

  5. nytrm
    Member
    Posted 1 year ago #

    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?

  6. keesiemeijer
    moderator
    Posted 1 year ago #

    Use conditional tags to enqueue only on the pages you want: http://codex.wordpress.org/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.

  7. nytrm
    Member
    Posted 1 year ago #

    Thanks, using conditional tags now.

  8. ampakine
    Member
    Posted 1 year ago #

    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.

  9. richarduk
    Member
    Posted 1 year ago #

    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.wordpress.org/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?

Topic Closed

This topic has been closed to new replies.

About this Topic