1

I am trying to change my custom logo url on wordpress to go to a different website. I have tried many different ways to do this with php and child themes but every time I try something it just breaks the site.

I have created a child theme and copied my header.php file.

Here is the section from the header.php file that talks about the custom logo:

            <div class="logo">
                <?php if( function_exists( 'the_custom_logo' ) && has_custom_logo() ) : ?>
                <figure class="logo-image">
                    <?php flash_the_custom_logo(); ?>
                    <?php if( get_theme_mod( 'flash_transparent_logo', '') != '') : ?>
                    <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
                        <img class="transparent-logo" src="<?php echo esc_url( get_theme_mod( 'flash_transparent_logo', '' ) ); ?>" />
                    </a>
                    <?php endif; ?>
                </figure>
                <?php endif; ?>

I am pretty new to php so I'm not super great at coding it but here are the things I have attempted with trying to change my logo url:

I believe this line needs to be changed from the code above:

   <a href="<?php echo esc_url( home_url( '/' ) ); ?>">

So I have tried these: (I am just using google for example purposes)

  <a href="<?php echo esc_url(https://www.google.com/); ?>">

  <a href="https://www.google.com/">

I saw from a thread a year ago that a filter could be an option like this one from the thread: How to change get_custom_logo() url? . However, I do not know where in there to put my new url.

add_filter( 'get_custom_logo',  'custom_logo_url' );
function custom_logo_url ( $html ) {

$custom_logo_id = get_theme_mod( 'custom_logo' );
$url = network_site_url();
$html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" 
itemprop="url">%2$s</a>',
    esc_url( $url  ),
    wp_get_attachment_image( $custom_logo_id, 'full', false, array(
        'class'    => 'custom-logo',
    ) )
);
return $html;    
}

If someone could help me figure this problem out I would really appreciate it. I have tried researching it and coding it myself but nothing has worked.

1

You just need to put your url in the href attribute of the link - like this (I used http://example.com):

            <?php if( function_exists( 'the_custom_logo' ) && has_custom_logo() ) : ?>
            <figure class="logo-image">
                <?php flash_the_custom_logo(); ?>
                <?php if( get_theme_mod( 'flash_transparent_logo', '') != '') : ?>
                <a href="http://example.com">
                    <img class="transparent-logo" src="<?php echo esc_url( get_theme_mod( 'flash_transparent_logo', '' ) ); ?>" />
                </a>
                <?php endif; ?>
            </figure>
            <?php endif; ?>
  • Hello, thank you for trying to help me with my question I really appreciate it. However, when I put this code in and went to click on my logo it turned my whole website white. You can go to my website but it's just a white screen now. I'll have to delete out the code to fix it again but do you know of another solution? – Cakers Sep 11 '17 at 16:17
  • The code above is perfectly fine, it does not cause any errors. The "white screen of death" is most likely caused by a PHP syntax error elsewhere in your file. Just put your full code (for that file) on pastebin and I'll take a look. – Mihai Papuc Sep 11 '17 at 19:21
  • Here is the Pastbin url: pastebin.com/gD0hXXVS Thank you for taking a look at it I really appreciate it. @Mihai Papuc – Cakers Sep 12 '17 at 15:53
  • The code has no syntax error. Could you also put the working code in pastebin? I will compare the two. But do make sure these are the only changes between the working version and the one that throws you the error. – Mihai Papuc Sep 12 '17 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.