diff --git a/functions.php b/functions.php index 6bb2774..65d088a 100644 --- a/functions.php +++ b/functions.php @@ -1033,3 +1033,53 @@ function preprocess_mathjax_content($content) } add_filter('the_content', 'preprocess_mathjax_content'); + +function customize_register($wp_customize) { + // Add setting to disable posts + $wp_customize->add_setting('disable_posts', array( + 'default' => false, + 'transport' => 'refresh', + )); + + // Add control for the setting + $wp_customize->add_control('disable_posts_control', array( + 'label' => __('Disable Posts', 'duck_behavior_journal'), + 'section' => 'title_tagline', + 'settings' => 'disable_posts', + 'type' => 'checkbox', + )); +} + +add_action('customize_register', 'customize_register'); + +function unregister_post_type() { + // Get the customizer setting + $disable_posts = get_theme_mod('disable_posts', false); + + // If the setting is enabled, unregister the post type + if ($disable_posts) { + unregister_post_type('post'); + } +} + +add_action('init', 'unregister_post_type', 20); + +function remove_post_menu_item() { + $disable_posts = get_theme_mod('disable_posts', false); + if ($disable_posts) { + remove_menu_page('edit.php'); + } +} + +add_action('admin_menu', 'remove_post_menu_item'); + +function exclude_posts_from_queries($query) { + if (!is_admin() && $query->is_main_query()) { + $disable_posts = get_theme_mod('disable_posts', false); + if ($disable_posts) { + $query->set('post_type', array('page')); + } + } +} + +add_action('pre_get_posts', 'exclude_posts_from_queries'); \ No newline at end of file