• 0

DMS 2 Adding custom CSS to single page template


Question

Posted · Report post

I'm building a careers page using a 3rd party plugin. I'd like to add a separate external style sheet to this page template because the styles are fairly voluminous and they don't apply to other pages.

 

Is that possible? Any other suggestions?

Share this post


Link to post
Share on other sites

3 answers to this question

  • 0

Posted · Report post

You can add page specific CSS by prefixing your CSS by using

.page-id-xxx 

Replace xxx with the ID of your page found in the Visual Editor > page setup. 

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Martin Davies thanks for the pointer, but I'm not entirely sure what you're suggesting? Are you saying I should add this in the custom CSS panel? Can you show me an example? Will this prevent that CSS from loading on other pages?

Thanks!

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

WordPress includes special classes that are assigned to the body tag. These special classes are dynamic as they're different on what page you're viewing on your WordPress site. For example,

 

if you view a category, the body class will have a category class for that category

if you view a post, it will have a unique class for that post, the same applies to pages etc...

 

You can use these classes to add individual styling for posts, pages, blog, category, archive and so forth. As Martin mentioned above, if you inspect your page using Google Chrome's dev tools, you will see a number of a classes in the body tag of your page/post.

It will look something like this page-id-41 (your id will be different most likely, so instead of 41 you will see a different value).

 

Now what you can do with this, is prefix your custom CSS with that class and this will allow you to add individual styling for that page or post.

 

For example, let's imagine you want to have a pink h1 on your about page. What you will need to do is go to your About page, then inspect the page using Chrome's dev tools and get the ID for that page.

 

Then use that in your code like so.

 

.page-id-666 h1 { color: pink; }

 

You can use the same principle for sections or sidebars. For example, lets say you want to give the Masthead sections title a unique color for your Contact us page. Again you inspect the page using dev tools, find the page id and use that class as a prefix in your CSS.

 

.page-id-123 .section-masthead h1 { color: #428BCA; }

 

This will give the Masthead sections title a bluish color for that page and that page alone.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now