How can I apply this CSS code to only one page on Wordpress?

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

I am trying to hide the scroll bar on one page of my wordpress website.

I have been trying with the following code

.body::-webkit-scrollbar { 
    display: none; 
}

However, this code is applying it to all pages on my site.

I tried doing what I normally would do which is to make something like this

.page-id-854 .body::-webkit-scrollbar { 
    display: none; 
}

But then the scroll bar is no longer hidden on any pages.

What can I do to make the code work on just .page-id-854 ?

profilepic.png
manpreet 2 years ago

 

You can use is_page, to determine what page you are on and then load your css based on that. Something like below:

if (is_page( 'Page Title' ) ) {
  // do something
}

Some other alternatives.

// When any single Page is being displayed.
is_page();

// When Page 42 (ID) is being displayed.
is_page( 42 );

// When the Page with a post_title of "Contact" is being displayed.
is_page( 'Contact' );

// When the Page with a post_name (slug) of "about-me" is being displayed.
is_page( 'about-me' );

/*
 * Returns true when the Pages displayed is either post ID 42,
 * or post_name "about-me", or post_title "Contact".
 * Note: the array ability was added in version 2.5.
 */
is_page( array( 42, 'about-me', 'Contact' ) );

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community