Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackpyle/9e6102b292b6d52fd7d5c1773a0c71c2 to your computer and use it in GitHub Desktop.
Save zackpyle/9e6102b292b6d52fd7d5c1773a0c71c2 to your computer and use it in GitHub Desktop.
Add Beaver Themer's location setting for Singular template as a body class of single-post_type to help with styling the Themer Layout
<?php
add_filter('body_class', function ($classes) {
if (is_singular('fl-theme-layout')) {
$current_post_id = get_the_ID();
$layout_type = get_post_meta($current_post_id, '_fl_theme_layout_type', true);
$location_settings = get_post_meta($current_post_id, '_fl_theme_builder_locations', true);
// Proceed only if the layout type is 'singular'
if ($layout_type === 'singular' && !empty($location_settings) && is_array($location_settings)) {
foreach ($location_settings as $location) {
// Extract the post type by removing 'post:' for each location.
$post_type = str_replace('post:', '', $location);
$classes[] = 'single-' . sanitize_html_class($post_type);
}
}
}
return $classes;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment