[theme-reviewers] Dynamic CSS and WP Customizer API

Justin Tadlock justin at justintadlock.com
Mon May 12 01:13:00 UTC 2014


Note that `wp_add_inline_style()` requires that you add the style in
addition to a style loaded via `wp_enqueue_style()`.  This is because the
function requires a valid handle from a stylesheet that's been loaded.
 This is certainly possible to do, but it may be easier to simply hook into
`wp_head`.

If you need a full, working example of using the Theme Customizer plus:

* CSS hooked to `wp_head`
* CSS added to the visual editor
* Use of the WP Cache API

See:
https://github.com/justintadlock/stargazer/blob/master/inc/custom-colors.php


On Sun, May 11, 2014 at 4:06 AM, Konstantin Kovshenin
<kovshenin at gmail.com>wrote:

> The way described in the article on CSS Tricks will not work for many
> WordPress installations. For example one where the name of wp-content
> or the themes folder is redefined in wp-config.php, or one where PHP
> scripts are not allowed to be executed within the whole wp-content
> directory for security reasons.
>
> That said, printing the styles inline might not be the best option,
> especially if there's a lot of them. You might want to try and do
> something like Jetpack Custom CSS does, i.e. watch for a $_GET
> variable very very early, like plugins_loaded or after_setup_theme in
> your case, dump your CSS and exit. You can even go further and add a
> rewrite rule to that tricks browsers into thinking your CSS is an
> actual styles.css file and treat it more like one, in other words -
> cache it.
>
> On Sun, May 11, 2014 at 4:44 AM, Chip Bennett <chip at chipbennett.net>
> wrote:
> > +1 for wp_add_inline_style() for dynamic (theme option or custom) CSS
> > overrides.
> >
> >
> > On Sat, May 10, 2014 at 6:32 PM, Sheri Bigelow <sheri at designsimply.com>
> > wrote:
> >>>
> >>> About the Theme Customizer API and dynamic CSS, I wondered if it was
> >>> better to add styles with wp_add_inline_style() or to add a dynamic
> css like
> >>> this and enqueue them with wp_enqueue_style() ?
> >>
> >>
> >> I think adding styles with wp_add_inline_style() would be better than
> >> generating CSS in a PHP file like in the example you linked to because
> the
> >> PHP route seems like more overhead to me plus it's an extra file where
> you
> >> don't need to make an extra file.
> >>
> >> _______________________________________________
> >> theme-reviewers mailing list
> >> theme-reviewers at lists.wordpress.org
> >> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
> >>
> >
> >
> > _______________________________________________
> > theme-reviewers mailing list
> > theme-reviewers at lists.wordpress.org
> > http://lists.wordpress.org/mailman/listinfo/theme-reviewers
> >
>
>
>
> --
> Konstantin
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20140511/70ee1f8e/attachment.html>


More information about the theme-reviewers mailing list