php - Change div class depending on page/post Wordpress -


is there easier way in wordpress?

what i'm trying change header class depending on page/post user on display different image..

my code - php

    <?php      //services page      if ( is_page( 'services' ) ) {      echo'<header class="main_top services_page">';       }      //portfolio page      else if ( is_page( 'portfolio' ) ) {      echo'<header class="main_top portfolio_page">';      }      //digital page      else if ( is_single( 'digital' ) ) {      echo'<header class="main_top digital_page">';      }      //social media page      else if ( is_single( 'social-media-2' ) ) {      echo'<header class="main_top media_page">';      }      //print page      else if ( is_single( 'print' ) ) {      echo'<header class="main_top print_page">';      }       //home page       else echo'<header class="main_top">';      ?> 

i have added different css class each header class below

  header.services_page{     background-image: url(images/contentmarketing1-2000x450.jpg);   }   header.portfolio_page{     background-image: url(images/portfolio-2000x450.jpg);   }   header.contact_page{     background-image: url(images/contact-2000x450.jpg);   }   header.digital_page{     background-image: url(images/digital2-2000x450.jpg);   }   header.media_page{     background-image: url(images/socialmedia-2000x450.jpg);   }   header.print_page{     background-image: url(images/print-2000x450.jpg);   }   header.audio_page{     background-image: url(images/audio-2000x450.jpg);   }   header.pr_page{     background-image: url(images/pr-2000x450.jpg);   }   header.cm_page{     background-image: url(images/contentmarketing2-2000x450.jpg);   } 

thanks! :-)

$page_post_title=get_the_title($page_post_id);  echo'<header class="main_top $page_post_title">'; 

this finish in 1 line.

try or can modify it.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -