Site logo

Archived topic

Custom Layout Options for pages

3 replies · Started by Achim on March 26, 2021

Viewing posts 1–4 of 4

Hi,

I'm looking for a simple way to easily customize individual pages in some parts. On these pages, for example, the logo, navigation, etc. should be light and not dark. Basically, I want to add a separate option in the "Layout" tab and I want to be able to change the setting per page. What would be enough for me would be a class in the body or something similar.

If I remember correctly it is always better to use hooks/filters instead of copying and editing a template. Therefore I want to avoid a separate template.

What is the best way here? Thanks in advance!

Hi there,

theres no easy way of adding extra options to the Layout Meta.
Simple method would be to use a Custom Field and the body_class filter.
This sample snippet looks for the meta key: custom_class and returns it value in the body classes:

add_filter( 'body_class', function( $classes ) {
  $custom_style_class = get_post_meta( get_the_ID(), 'custom_class', true );

  if ( $custom_style_class ) {
     $classes[] = $custom_style_class;
  }
return $classes;
} );

you can of course register your own meta box to create a UI for it - or use a plugin like this to do the work for you:

https://en-gb.wordpress.org/plugins/meta-box/

Hi David,

awesome, thanks for your super fast response and for pushing me in the right direction. I‘ll use to body_class filter in combination with ACF, which is activated anyway.

Best,
Achim

Glad to be of help!

This archived topic is closed to new replies.