Non-Graphene Question – Internal Styles in a WordPress Site
I’ve been using WP for quite some time and have never figured this out. How can I use Interal styles for just the specific post or page that I am working on? If I want to use a certain effect for that one post or page, is there a way to do it besides adding it to the child stylesheet?
To sum up my real concern I guess, let’s say that I have four pages that contain four tables, and I want to have all of those tables styled totally different. We know that table styles can get rather lengthy if a lot of styling is done. So, how could I add those styles in the head element internally, instead of on the external child stylesheet, therefore, not having to have hundreds of lines of styles called on possibly hundreds of pages that they are not needed on? Would it just be best to enqueue a specific stylesheet in the functions file for that one page?
In-line styles are the only alternative I’ve found but I do not like it. It clutters up the page.
Now please understand that for me this is really a big hypothetical, but in the future it may not be, and I do not want to have go back and do things right that I’ve done “not so right.”
Thanks for any help. Any ideas and suggestions are appreciated.Mod
WordPress assigns each and every page, post, widget, menu item, etc., its own unique ID. It’s a simple matter of using “view source” or the Firebug addon for Firefox to figure out what that ID is.
This has been discussed many times in this forum. Have a search, and I’m sure you’ll find plenty of examples for how to achieve this.Admin
On top of Ken’s reply, if you want the additional CSS for a particular page to appear only on that page and not on any other pages, you’ll have to insert the CSS onto the page using PHP, by checking for the current page being displayd. This can be achieved via a child theme’s
functions.phpfile, but I’d say that it’s more trouble than worth it.
With GZip compression these days, a few hundred lines of CSS codes do not constitute much of an additional page size to be downloaded. In fact, it would be a greater hit to performance to serve the CSS codes as a separate file due to the additional HTTP request that needs to be sent to the server.
Ok, thanks for the answers. Syahir, I have back when I was just fiddling around, used an if statement to enqueue stylesheets for specific pages, but then of course it was just more files to retrieve, and yes, like you say, it was more trouble than it was worth. So I just combined them.
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.