Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8120959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:19:42+00:00 2026-06-06T05:19:42+00:00

I am looking how to change a logo based on either class in the

  • 0

I am looking how to change a logo based on either class in the <body> or post type/page template.
I am not too knowledgeable with PHP if statements which I am guessing I will need to make this work.

I think what would work great is if I had all the logos in a sprite graphic and using a css class to change to the different logos for each page so the php would just change the class.

Something along like this?

if(body class="home") {
  <div class="logo1"><img src="images/logo.png" /></div>
} elseif(body class="page1") {
  <div class="logo2"><img src="images/logo.png" /></div>
} else {
  <div class="logo"><img src="images/logo.png" /></div>
}

I have not tried this code yet just want to know if this correct way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:19:44+00:00Added an answer on June 6, 2026 at 5:19 am

    iambriansreed answered well before me, and has provided a good answer but I want to expand on what he said, and I have more to say than will fit in a comment, so I am posting my own answer.

    In your HTML you would have a single logo element e.g. a div or an h1 tag:

    <h1 class="logo">My Company</h1>
    

    Then using CSS you would hide the text, and replace it with an image:

    .logo {
        background: url(mylogo.png) 0 0 no-repeat;
        width: 200px; /* match logo width */
        height: 80px; /* match logo height */
        text-indent: -9999px; /* hides text */
    }
    

    I’ve shown one technique for hiding the text. There are other ways. The reason for leaving the text in the markup is for SEO and accessibility.

    On sub pages you would use a more specific selector, based on the class attached to your body tag, to alter the logo background:

    .section2 .logo {
        background: url(mylogo.png) 0 -80px no-repeat;
    }
    

    PHP doesn’t come into the equation except to attach the unique class to the body tag based on which section/page is being rendered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to change the screen orientation based on device type. The case is
I am looking to change min-height attribute of textwidget class, to adjust the height
I'm looking to change a javascript variable on page load with Greasemonkey. The variable
I'm looking to change my application to store PHP Session data in MySQL. The
I'm looking to change the background-color for ALL cells with class=bg when hovering ANY
Looking for a way to either: Change one of the fields of a new
I'm looking to change the phone's rotation based on the size of an image.
I'm looking to change the number of columns my tableview has without subclassing it.
I am looking to change the group names in a crystal report to a
I am looking for a way to change the value of the DisplayName attribute

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.