Custom css on top nav for specific page wordpress

I am new to wordpress theme development and I need to style the main navigation menu depending on what page the user is on.

Simply put, only the home page has a unique styling on it and all other pages will have a different css. I have tried adding this in my functions.php but it does not work.

Read More
if (is_page( 52 ) ):
    wp_enqueue_style('style1_css', get_template_directory_uri() . '/css/style1.css' );
endif;

Sorry if its badly explained!

Related posts

4 comments

  1. <?php // TOP PICTURE DEFINITION FOR ARTICLES PAGE
            if ( is_page()) {
               wp_enqueue_style('style1_css', get_template_directory_uri() . '/css/style1.css' );
            }
    ?>
    

    Use like this for detailed reference kindly refer this link click_here

  2. You can link one css file for all pages and use more specific selectors (with binging to css-classes) for css ruling:

      .nav {/* for all pages */
        ...
      }
     
      .home .nav { /* for home page */
        ...
      }
  3. Target only the home class like:

    .home .nav { 
     // CSS STUFF
    }
    

    And if you want all nav classes, use:

    .nav { 
     // CSS STUFF
    }
    
  4. fixed it by adding
    

    nav <?php if ( is_page('52')) { echo 'class="homeNav"'; } ?>>

Comments are closed.