• [ Moderator note: moved to Fixing WordPress. Please do not use Developing with WordPress for these topics. ]

    Hi, I have a client who wants to have a custom CSS stylesheet load for certain pages ONLY. I know how to create a custom page template, but I need three of these, and each one needs to reference a different CSS and load different code (have different head info.) What would be the best way to go about doing that?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You could selectively load stylesheets using wp_enqueue_style() within conditional structures based on the value returned by get_queried_object_id(). Code that basically says “if the queried page ID is X, then enqueue stylesheet foobar.css” Or whatever.

    You could also manage everything with a single stylesheet and by using appropriate selectors and style placement. With most themes, there is always a unique body class on every page, something like page-id-xxx. Including this class as part of the CSS selectors will ensure the associated styles are only applied to that one page whose ID matches the number replacing xxx.

    All other things being equal, the last listed style is applied in preference to any conflicting styles that occurred earlier. Thus ensure your page specific styles are applied after the generic styles for other pages.

Viewing 1 replies (of 1 total)

The topic ‘Custom Headers’ is closed to new replies.