How to find WordPress Post/Page ID

It is very easy to find WordPress Post/Page ID, only 3 steps:

  • Login wp-admin, go to Pages(or Posts) > All
  • Move the mouse cursor to a page(or Posts) title, there will be a URL shown on the bottom status bar of the browser
  • You will see a number like the 613. It is the ID
WordPress Post/Page ID

Add Unique Custom Styles to One WordPress Page or Post

Sometimes, you may wish to add styles to only a certain page. At this time, we need to find the WordPress Post/Page ID. WordPress assigns a unique ID to each post/page, so we can take advantage of this feature. The class name with the unique ID will be exported on the <body> tag on some WordPress themes like: SEA, Art, Arnold, Air.

WordPress will give the Post(Portfolio) above a body class of postid-613, give the Page a body class of page-id-613

You can see the classes added if you View Source for your page or post.

If your WordPress theme does not supply the body class, please add the PHP codes into your WordPress theme functions.php (or by code snippets plugin):

add_filter( 'body_class','my_body_classes' );
function my_body_classes( $classes ) {
    $classes[] = 'your-class';
    return $classes;
}

If your style.css has styles for body background color white, the CSS will look like this:

body {
 background-color: #fff;
}

Now suppose a Page has an ID of post=25. And you want to make a light gray background. You would style it using the body class of .page-id-25. You can add the following to the bottom of your style.css or in Appearance > Customize > Additional CSS.

body.page-id-25 {
 background-color: #eee;
}

Want to Hire a Professional WordPress Developer ? Please Click Here.

Was this article helpful?

Related Articles