Created
April 7, 2024 18:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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