Last Updated on: June 3, 2024

Disable WordPress Blog Features with a PHP Code Snippet

This code snippet disables all blog-related features in a WordPress site to ensure it functions purely as a business site without blogging capabilities for the admin or front-end users.

Please add this code snippet to your theme's functions.php file or a custom plugin or a snippet management plugin to ensure all blog-related features are completely disabled.

<?php
// Disable support for posts
function disable_post_support() {
    remove_menu_page('edit.php'); // Remove the 'Posts' menu item
    remove_menu_page('edit-comments.php'); // Remove the 'Comments' menu item
}
add_action('admin_menu', 'disable_post_support');

// Remove post-related metaboxes from the dashboard
function remove_post_dashboard_widgets() {
    remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); // Quick Draft
    remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side'); // Recent Drafts
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal'); // Recent Comments
}
add_action('wp_dashboard_setup', 'remove_post_dashboard_widgets');

// Remove post-related widgets from the front-end
function unregister_post_widgets() {
    unregister_widget('WP_Widget_Recent_Posts');
    unregister_widget('WP_Widget_Recent_Comments');
}
add_action('widgets_init', 'unregister_post_widgets');

// Remove post-related options from the Customizer
function remove_post_customizer_options($wp_customize) {
    $wp_customize->remove_section('custom_css'); // Remove 'Additional CSS'
    $wp_customize->remove_panel('widgets'); // Remove 'Widgets'
}
add_action('customize_register', 'remove_post_customizer_options');

// Remove post and comment feeds
function disable_post_feeds() {
    wp_redirect(site_url());
    exit();
}
add_action('do_feed', 'disable_post_feeds', 1);
add_action('do_feed_rdf', 'disable_post_feeds', 1);
add_action('do_feed_rss', 'disable_post_feeds', 1);
add_action('do_feed_rss2', 'disable_post_feeds', 1);
add_action('do_feed_atom', 'disable_post_feeds', 1);

// Remove post type support for 'post'
function remove_post_type_support_custom() {
    remove_post_type_support('post', 'editor');
    remove_post_type_support('post', 'thumbnail');
    remove_post_type_support('post', 'excerpt');
    remove_post_type_support('post', 'trackbacks');
    remove_post_type_support('post', 'custom-fields');
    remove_post_type_support('post', 'comments');
    remove_post_type_support('post', 'revisions');
    remove_post_type_support('post', 'author');
    remove_post_type_support('post', 'page-attributes');
    remove_post_type_support('post', 'post-formats');
}
add_action('init', 'remove_post_type_support_custom', 10);

// Remove 'New Post' from admin bar
function remove_new_post_from_admin_bar($wp_admin_bar) {
    $wp_admin_bar->remove_node('new-post');
}
add_action('admin_bar_menu', 'remove_new_post_from_admin_bar', 999);

// Hide categories and tags from the admin menu
function remove_taxonomies_admin_menu() {
    remove_menu_page('edit-tags.php?taxonomy=category'); // Remove the 'Categories' menu item
    remove_menu_page('edit-tags.php?taxonomy=post_tag'); // Remove the 'Tags' menu item
}
add_action('admin_menu', 'remove_taxonomies_admin_menu');

// Redirect users away from specific admin pages
function redirect_specific_admin_pages() {
    global $pagenow;

    // List of admin pages to redirect from
    $redirect_pages = array(
        'edit.php',          // Posts list
        'post-new.php',      // New Post
        'edit-comments.php', // Comments list
        'edit-tags.php',     // Categories and Tags
    );

    // Check if the current page is one of the specified admin pages and not a custom post type page
    if (in_array($pagenow, $redirect_pages) && !isset($_GET['page']) && empty($_GET['post_type'])) {
        wp_safe_redirect(admin_url());
        exit;
    }
}
add_action('admin_init', 'redirect_specific_admin_pages');
?>

Summary

This code snippet ensures that all blog-related functionalities are completely disabled to the admin or front-end users while other features of the website remain unaffected.

Here is a summary of what each part does:

  1. Disable Support for Posts: Removes the 'Posts' and 'Comments' menu items from the WordPress admin menu.
  2. Redirect Post and Comment Admin Pages: Redirects any attempts to access post or comment admin pages back to the WordPress admin dashboard.
  3. Remove Post-Related Metaboxes: Removes the Quick Draft, Recent Drafts, and Recent Comments metaboxes from the WordPress dashboard.
  4. Unregister Post-Related Widgets: Unregisters the Recent Posts and Recent Comments widgets from the front-end.
  5. Remove Post-Related Options from the Customizer: Removes the 'Additional CSS' section and 'Widgets' panel from the WordPress Customizer.
  6. Disable Post and Comment Feeds: Redirects any post or comment feed requests back to the site’s home page.
  7. Remove Post Type Support for 'post': Disables various post type supports, including the editor, thumbnail, excerpt, trackbacks, custom fields, comments, revisions, author, page attributes, and post formats.
  8. Remove 'New Post' from Admin Bar: Removes the 'New Post' option from the WordPress admin bar menu.
  9. Hide Categories and Tags from Admin Menu: Removes the 'Categories' and 'Tags' menu items from the admin menu.
  10. Redirect Category and Tag Admin Pages: Redirects any attempts to access category or tag admin pages back to the WordPress admin dashboard.

This effectively converts a WordPress site into a non-blogging platform, suitable for business or other types of websites where blogging features are unnecessary.

0 Shares
SyncWin Logo
SyncWin is a dedicated place to explore the Content, Discussions, & Useful Details around topics like Business, Technology, and Lifestyle to help you learn and grow in your life.
About Us
Made with ❤ for WinSyncers
Copyright © 2018 - 2024 by SyncWin | All Rights Reserved.
crossmenuarrow-right
0 Shares
Copy link