How To Target A Specific Page or Post Type ID In Divi with CSS Tutorial by Pee Aye Creative

How To Target A Specific Page or Post Type With CSS In Divi

Nelson Miller Pee Aye Creative
Sometimes you need to target a specific page or item on a page of your Divi website with CSS. This short tutorial will show you how to do that very easily!

1. Target Individual Pages or Posts With CSS

The best way to target a specific page with CSS in Divi is to first find the ID of the page. This can be found in several ways.

A. Find Page ID From the “Edit Page” slug

The simplest way to find the CSS class of the page you want to target is to find the page ID in the slug of the page editor. This is super easy to find. Just go to the page you want to target, edit the page, and look in the address bar for something like this: https://yourdomain.com/wp-admin/post.php?post=291&action=edit

Do you see any numbers? That’s right! The page ID that you need for your CSS is right there, 291.

So how would this be used? The number gets added to the CSS selector of “.page-id-“ and becomes “.page-id-291”

So an example would be like this:

.page-id-291 {
background: red;
}

Where To Paste The CSS Code

1. Divi Assistant
If you are using our Divi Assistant plugin, simply paste the code in the CSS tab in the custom code window in the Divi Visual Builder.

2. Child Theme
If you are using a child theme, paste this code into the style.css file. If you don't have a child theme, you can generate a child theme directly on your site or download our free child theme.

3. Divi Theme Options Integration
Otherwise, paste this code in your Divi>Theme Options>Custom CSS code box.

If you need help understanding where to paste the code, please check out our complete guide about where to add custom code In Divi.

Now this page is the only page on your website that will have the background color of red applied to it. This can be very handy for targeting more specific elements on your page like the header or menu item.

NOTE: For blog posts, it will be very similar, but the CSS selector will be “postid-“ instead, so for example “.postid-52”

B. Find Page ID Using the browser’s Inspect tool

This other method is for those how are familiar with the browser inspect tool. When you right-click on your website, you will see something like “inspect” or “inspect element.” Click on that and look for a button in the new, scary-looking code popout that looks like a mouse pointer. Select that pointer and click something on the page. Then, in the code popout, look for something near the top that starts with this:

<body class=”page-template-default page page-id-291 etc. etc.

Did you notice it? There it is, the “.page-id-291” that we need to target this Divi page with CSS. You can apply your CSS the same way as in the previous example.

Again, this is the same for blog posts. Just look for the “postid” on in the code.

Subscribe For More Things Like This!

At the start of each month, we send out a recap newsletter from the month before with family news, Divi news, our latest tutorials, and product news. Occasionally, if the news is too exciting to wait, we will send out another email separate from the monthly newsletter. That’s what you get when you subscribe, and of course you can unsubscribe if you are no longer interested!

Blog Post Optin

Please share this post!

Leave A Response!

By commenting you agree to our Blog & YouTube Comments Policy

0 Comments

Submit a Comment

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

Recent Posts

0

Your Cart