While I understand that there are many similar questions answered which helped me find a solution to update the page template for my custom post type pragmatically and it works correctly.
However, my difficulty is in finding a solution to update the body_classes
that matches the page template. Right now, the body classes are not updated when the page template is updated pragmatically.
add_filter( 'template_include', 'my_template_include', 99, 1 );
function my_template_include( $template ) {
global $post;
$meta = get_post_meta( $post->ID, 'designblocks-product-template', true );
if ( ! $meta ) {
return $template;
}
$get_template = get_post_meta( $meta, '_wp_page_template', true );
if ( $get_template ) {
$template = locate_template( array( $get_template ) );
}
return $template;
}
Any ideas?
<body <?php body_class( trim( $body_classes ) ); ?>>
where you could prepare your own $body_classes.