Usually if you want to customise a post (generic: ie all) type in WordPress you would create a custom page template for it ie, following the template hierarchy, a page will be customised based on it's name and where it falls in that hierarchy. The further to the left in the following template graphic, the first it will get chosen. If I've ever needed to create a custom page format, that's what I've done.
With pages
(and not posts
) you can pick a "default" template that applies to the page. This usually relates to whether the page will have a sidebar or not, being that the default will have a sidebar and there will usually be another option for "full width".
I have recently used a plugin that has a nice feature of making each page unique in the front end editor. Something that I thought would only be possible through a custom page/post template file for that content.
That is to say, that without creating a custom post type, or template file, the plugin utilises some hook whereby the page format is custom altered for that post only.
I want to do something similar where I can dictate that the majority of my pages follow the standard format, but for some pages that are in some way or other identified I want that format changed and I'd prefer that to be by way of hook or filter, and done not through extra pages.
The changes are largely CSS based.
Ideally, I'd like to have a dropdown similar to the "default template" metabox that allows me to pick which one to use and be applied to that page.
For the sake of argument and example, the default would be unchanged, and another choice would change the max-width
and background-color
of the .col-ful
class as well as an extra widget area between the content and the footer.
I know I could just create a custom page type and use it for those pages, but I want to still be able to utilise the custom naming principle of the hierarchy to allow for further customisation of the page if necessary. ie, I want it to behave on the outside of the content like the default template dropdown, but still allow customised content formats that the named page types allow. PLUS I want the template to be available across multiple post types, not just pages.
edit: I like the idea proposed by LSW-Mo in the comments, and initially I thought it would work, however, the property I need to modify is higher up in the .col-ful
classed div
(highlighted in the image). I want to override the max-width
attribute which is just set way too low for my liking (visible higher in the right pane).
If anyone could suggest how to modify that in a manner as per described by LSW-Mo, that would be appreciated.
add_filter
call topost_class
to add the saved/selected classname to the post/post-markup. Codex Link to post_class. After that you just need to write some custom CSS code, as your post-markup should look like<article id="post-14" class="post-14 post type-post status-publish hentry mycustomclassforstyling">
..col-ful
class which sets the overall page width in the wooCommerce theme.body_class
instead ofpost_class
body_class
instead ofpost_class
I was able to get it working.