Support » Themes and Templates » Hooking enqueued styles into template_redirect or wp?

  • Hey guys,

    This is kind of a general WP Theme coding question.

    I have a Child Theme that has a function which enqueue’s its stylesheet and then hooks into the template_redirect hook. This works in most cases, but occasionally a user of such Child Theme runs into instances where this doesn’t work. For example, a Plugin which has Custom Page Templates and styles that hook into template_redirect at a higher priority. In these cases the Child Theme’s stylesheet never gets hooked in (“The Events Calendar” Plugin and I think BBPress does this).

    So one solution has been to hook this stylesheet function into the ‘wp’ hook, but I wasn’t sure if this could cause other issues in the future. I know this hook location is after the posts query, but before the template execution so it would seem like an ideal place, but I wasn’t sure if there might be cases where this could be a bad idea.

    So my question is, can anyone think of a situation where this might not be ideal or just in general, does this raise any red flags for anybody?

    Thanks for any input. 🙂

    Eric

Viewing 1 replies (of 1 total)
  • OK, so I’ve already found one issue with hooking into ‘wp’ and that’s the fact that it then shows up in the admin pages. I know there are ways around this (eg. !is_admin()) but that’s all I needed to see to determine that template_redirect is still the most ideal WP Hook for Theme Stylesheets. At least for what I’m doing.

    Eric

Viewing 1 replies (of 1 total)
  • The topic ‘Hooking enqueued styles into template_redirect or wp?’ is closed to new replies.