Find the class of a WordPress page

February 3, 2019
Task: Identify a WordPress webpage's CSS class
Difficulty: Apprentice

Questions Answered

  1. How do I find a specific page's class on a WordPress website?

Topics

CSS, Inspector

I like the Extra theme from Elegant Themes, but it's far from perfect. This isn't a review but I'm working towards it. An example of something I don't love is that the Project post type is created automatically whether you want it or not.

In some cases, you absolutely don't want it there. People are going to mess with it. If it's there, people are going to ask about it. Plus, it's extra clutter. Pun intended.

Existing solutions

You can easily find how to hide or remove the Projects post type from Divi. It just takes a quick trip over to Google. But I couldn't find a solution for the Extra theme. Why not?

  1. There isn't 1.
  2. No one wrote it down.
  3. It's hard to find because the theme name, Extra, is a common word.
  4. The solution is the same for Extra as it is for Divi.

I'm guessing the answer is a combination of 2, 3, and 4. But I had to test the code to see if option 4 was true.

The original code for Divi

I found some code for removing the Project post type from Divi over at Mad Lemmings.

The code keys off a function named et_pb_register_posttypes. Sure enough, that function exists in Extra, too.

The test and results

I added the script to my child theme's functions.php file, saved it, and reloaded the site's admin section.

Poof! Projects were gone. I poked around the site and everything (well, everything except for projects) seemed to be working fine.

The standard edit your code at your own risk disclaimer

Whenever you edit your code, you risk breaking breaking something. That is why should never work on your live website.

Steps you can take to protect yourself in case something goes wrong:

  1. Back up the site.
  2. Make copies of the files you're editing.
  3. Test your work on a development/staging site.
  4. Do all theme customization on a child theme.
  5. Edit via external text editor. If you are editing via WordPress and WordPress goes down, you can't fix your error.
  6. Put custom code in your own plugin. Do not make edits to existing plugins.

The code


if ( ! function_exists( 'et_pb_register_posttypes' ) ) :
	function et_pb_register_posttypes() {
		global $wp_post_types;
		if ( isset( $wp_post_types[ $post_type ] ) ) {
			unset( $wp_post_types[ $post_type ] );
			return true;
		}
	return false;
	}
endif;

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Last Updated On: February 07, 2019

Pin It on Pinterest