Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: wp_enqueue_style() or <link rel= ...... ?

  1. #11
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    To be honest I can't think of any real-world use for using wp_enqueue_style() in this way, but I've often never seen the use in doing certain things and it's turned out later that if I'd added that extra flexibility to the system it was useful to someone, somewhere.

    Plus it feels kinda weird to use wp_enqueue_style() to load every stylesheet EXCEPT the most important one.

    Quote Originally Posted by Otto View Post
    Ryan: You should use get_stylesheet_uri() instead of get_stylesheet_directory_uri() . '/style.css', because of the stylesheet_uri filter.
    Oops! I'll fix my code above :)

  2. #12
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,997

    Default

    Quote Originally Posted by Ryan View Post
    To be honest I can't think of any real-world use for using wp_enqueue_style() in this way, but I've often never seen the use in doing certain things and it's turned out later that if I'd added that extra flexibility to the system it was useful to someone, somewhere.

    Plus it feels kinda weird to use wp_enqueue_style() to load every stylesheet EXCEPT the most important one.
    It could make perfect sense. The style.css file is the master. Hard-linking it in the document head ensures that any stylesheets enqueued in wp_head() will load *after* it, and therefore facilitate over-riding the master style sheet. If everything is loaded via wp_enqueue_script(), you'd have to pay careful attention to the prioritization of each enqueued style sheet.
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  3. #13
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    Quote Originally Posted by chipbennett View Post
    It could make perfect sense. The style.css file is the master. Hard-linking it in the document head ensures that any stylesheets enqueued in wp_head() will load *after* it, and therefore facilitate over-riding the master style sheet. If everything is loaded via wp_enqueue_script(), you'd have to pay careful attention to the prioritization of each enqueued style sheet.
    Ohhh, smart thinking! As a flip-side to that then, what if someone wants to insert their plugin CSS before the themes CSS, so that the theme can over-ride it?

    You could make the theme load a little earlier than the rest by using the priority argument in add_action(). I'll update my code above to include that as a feature.

  4. #14
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,997

    Default

    Quote Originally Posted by Ryan View Post
    Ohhh, smart thinking! As a flip-side to that then, what if someone wants to insert their plugin CSS before the themes CSS, so that the theme can over-ride it?
    Well, in an ideal world, the master style.css is perfectly, minimally specified, as would Plugin-custom CSS, which would still allow for the end user easily to override the Plugin's CSS.

    (If only we lived in an ideal world...)

    You could make the theme load a little earlier than the rest by using the priority argument in add_action(). I'll update my code above to include that as a feature.
    That's a good addition.
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  5. #15
    benhuson is offline Hello World
    Join Date
    Feb 2010
    Location
    London, UK
    Posts
    11

    Default

    I can see there would be a benefit if you wanted to detect the browsing device server side and include a mobile-only stylesheet instead of the main stylesheet - the benefit being that this would cut down requests and KBs when on a mobile connection. However if your main stylesheet contains only simple css common to both mobile and desktop then, you could just enqueue extra styles on top of this.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •