WordPress is a powerful and flexible platform that allows you to create and manage different types of websites. One of the features that WordPress offers is the ability to organize your posts into categories and subcategories. This can help you improve the structure, navigation, and SEO of your site.

However, sometimes you may want to hide or style your subcategories in WordPress to make your site look more professional, clean, and user-friendly. For example, you may want to hide the subcategories from your homepage, sidebar, or menu, or you may want to change their appearance, color, or font.

In this article, we will show you how to hide or style your subcategories in WordPress using different methods. You can choose the one that suits your needs and preferences.

Method 1: Hide or Style Your Subcategories in WordPress Using CSS

CSS stands for Cascading Style Sheets, and it is a language that defines how the elements of a web page are displayed. You can use CSS to customize the look and feel of your WordPress site, including your categories and subcategories.

To hide or style your subcategories in WordPress using CSS, you need to add some custom CSS code to your site. You can do this in three ways:

  • Using the WordPress Theme Customizer
  • Using a child theme
  • Using a plugin

Using the WordPress Theme Customizer

The WordPress Theme Customizer is a tool that allows you to preview and modify the appearance of your site without affecting the live version. You can access it by going to Appearance » Customize from your WordPress dashboard.

To add custom CSS code using the Theme Customizer, follow these steps:

  • Click on Additional CSS at the bottom of the left panel.
  • Paste your custom CSS code in the box on the right.
  • Click on Publish to save your changes.

Here are some examples of custom CSS code that you can use to hide or style your subcategories in WordPress:

To hide all subcategories from your site, use this code:

.children { display: none; }

To hide subcategories only from your homepage, use this code:

.home .children { display: none; }

To hide subcategories only from your sidebar, use this code:

.widget_categories .children { display: none; }

To change the color of your subcategories, use this code:

.children a { color: #ff0000; /* Change this to any color you want */ }

To change the font size of your subcategories, use this code:

.children a { font-size: 14px; /* Change this to any size you want */ }

To change the font style of your subcategories, use this code:

.children a { font-family: Arial; /* Change this to any font you want */ }

You can also combine multiple CSS properties to create more complex styles for your subcategories. For example, to make your subcategories bold, italic, and underlined, use this code:

.children a { font-weight: bold; font-style: italic; text-decoration: underline; }

Using a Child Theme

A child theme is a copy of a parent theme that inherits its functionality and design. You can use a child theme to make changes to your site without affecting the original theme. This way, you can preserve your customizations even if you update the parent theme.

To create a child theme, you need to have some basic knowledge of HTML, CSS, and PHP. You also need to have access to your site’s files via FTP or cPanel. If you are not comfortable with these steps, you can skip this method and use one of the other options.

To create a child theme and add custom CSS code using a child theme, follow these steps:

  • Connect to your site’s files via FTP or cPanel and go to the wp-content/themes folder.
  • Create a new folder and name it after your parent theme followed by -child. For example, if you are using the Twenty Twenty-One theme, name it twentytwentyone-child.
  • Inside the new folder, create a file called style.css and open it with a text editor.
  • Paste the following code at the top of the file:

/* Theme Name: Twenty Twenty-One Child Template: twentytwentyone */

  • Replace Twenty Twenty-One Child with the name of your child theme and twentytwentyone with the name of your parent theme.
  • Save and close the file.
  • Inside the same folder, create another file called functions.php and open it with a text editor.
  • Paste the following code inside the file:

<?php add_action( ‘wp_enqueue_scripts’, ‘enqueue_parent_styles’ ); function enqueue_parent_styles() { wp_enqueue_style( ‘parent-style’, get_template_directory_uri().‘/style.css’ ); } ?>

  • Save and close the file.
  • Go back to your WordPress dashboard and go to Appearance » Themes.
  • Activate your child theme by clicking on it.
  • Go to Appearance » Theme Editor and select your child theme from the dropdown menu at the top right corner.
  • Click on the style.css file on the right panel and paste your custom CSS code at the bottom of the file.
  • Click on Update File to save your changes.

Using a Plugin

If you don’t want to deal with code, you can use a plugin to add custom CSS code to your site. There are many plugins that allow you to do this, but we recommend using Simple Custom CSS and JS, which is a free and easy-to-use plugin.

To add custom CSS code using Simple Custom CSS and JS, follow these steps:

  • Install and activate the plugin from your WordPress dashboard.
  • Go to Custom CSS & JS » Add Custom CSS.
  • Give your custom CSS code a title and paste it in the editor.
  • Click on Publish to save your changes.

Method 2: Hide or Style Your Subcategories in WordPress Using a Plugin

Another way to hide or style your subcategories in WordPress is to use a plugin that is specifically designed for this purpose. There are several plugins that can help you with this, but we recommend using Ultimate Category Excluder, which is a free and simple plugin that allows you to exclude categories and subcategories from various parts of your site.

To hide or style your subcategories in WordPress using Ultimate Category Excluder, follow these steps:

  • Install and activate the plugin from your WordPress dashboard.
  • Go to Settings » Category Excluder.
  • Here you can select which categories and subcategories you want to exclude from different parts of your site, such as the front page, the archives, the feeds, or the search results.
  • Check the boxes next to the categories and subcategories that you want to hide and click on Update.

Conclusion

In this article, we have shown you how to hide or style your subcategories in WordPress using different methods. You can choose the one that works best for you and your site.

We hope this article was helpful for you. If you have any questions or feedback, please let us know in the comments below.

Categorized in:

Tagged in:

, ,