0

Many time i have found a lot of solution on this pages and thanks for every help! I hope i can found one more new! :-)

I need change logo in header, Now, when js work make a new class, with css I make a new layout but the logo is in php file...

So: when the page scroll the header change, but i can not change the logo in the header because is in php and with the css i cann't found a solution

This is the php code:

<!-- header -->
<header class="header clear" role="banner">

    <!-- logo -->
    <div class="logo">
        <a href="<?php echo home_url(); ?>">
            <img src="<?php echo get_template_directory_uri(); ?>/img/logo.png" alt="Logo" class="logo-img">
        </a>

    </div>
    <!-- /logo -->

this is the js (i don't know if need to know)

$(document).ready (function () {
    $(window).scroll (function () {
        var sT = $(this).scrollTop();
            if (sT >= 100) {
                $('.header').addClass('cambio_header')
            }else {
                $('.header').removeClass('cambio_header')
            }
    })
})

Some one have idea how write the php? (the web site is make whit Wordpress)

Thanks so much!

2
  • I don't understand what you are trying to do. You can always use jQuery to change the logo src attribute. e.g. $('.header .logo img').attr('src','something'); Commented Oct 29, 2015 at 12:55
  • I want change the logo in the header, but i cann't, i don't know how change this php code. or what ever. anyway thanks for reply. I'm don't know how use jqery in this case. Commented Oct 29, 2015 at 13:00

2 Answers 2

1

You could change the image in your javascript:

$(document).ready (function () {
    var logo-top = '/url/to/logo.jpg';
    var logo-scroll = 'url/to/logo-scroll.jpg';
    $(window).scroll (function () {
        var sT = $(this).scrollTop();
            if (sT >= 100) {
                $('.header').addClass('cambio_header').find('img.logo-img').attr('src', logo-scroll);
            }else {
                $('.header').removeClass('cambio_header').find('img.logo-img').attr('src', logo-top);
            }
    });
});

Or you could add both logos in the php file, and hide/show them with a css rule

<div class="logo">
    <a href="<?php echo home_url(); ?>">
        <img src="<?php echo get_template_directory_uri();?>/img/logo.png" alt="Logo" class="logo-img">
        <img src="<?php echo get_template_directory_uri();?>/img/logo-scroll.png" alt="Logo" class="logo-img scroll">
    </a>
</div>

.header .logo-img.scroll{
    display:none;
}
.header.cambio_header .logo-img{
    display:none;
}
.header.cambio_header .logo-img.scroll{
    display:block;
}
Sign up to request clarification or add additional context in comments.

6 Comments

Great, glad i could help you
You have taught me something good today! I don't have thinks to add a class and play with that! Only try to use if and elsa, but lost me in this!
which php file is that?I mean that you added the above code?
@spy depends on your theme, but most likely header.php
@Steve Thanks for your time.Also where do i find that specific javascript in my theme?I ve checked in the js file but i cant tell which one is the one responsible for the sticky header
|
0

I think that better way could be to place logo in CSS and in PHP will be only container for this logo. Then, when you will change the CSS, logo will be also changed.

<div id="logo-container"></div>

#logo-container {
    width: logo_width;
    height: logo-height;
    background: url('path/ot/logo') cover;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.