Support » Theme: OceanWP » How to set custom link for logo

  • Hi,

    I have my supplementary blog site installed on a sub-domain. By default, my blog site logo contains the link of my blog homepage. But I want to set the logo link to the original main website on my primary domain. So I need to set a custom URL for my logo in header. Is there any way?

    Thanks.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Theme Author oceanwp

    (@oceanwp)

    Hello, try this code in the functions.php file of your child theme:

    function my_custom_logo_link() {
        $custom_logo_id = get_theme_mod( 'custom_logo' );
        $html = sprintf( '%2$s',
                esc_url( 'oceanwp.org' ),
                wp_get_attachment_image( $custom_logo_id, 'full', false, array(
                    'class' => 'custom-logo',
                ) )
            );
        return $html;   
    }
    add_filter( 'get_custom_logo', 'my_custom_logo_link' );

    Well I did replace the “oceanwp.org” with my custom url. No luck!

    Theme Author oceanwp

    (@oceanwp)

    This code works, just replace by your own url:

    function my_custom_logo_link() {
        $custom_logo_id = get_theme_mod( 'custom_logo' );
        if ( $custom_logo_id ) {
    	    $custom_logo_attr = array(
    			'class'    => 'custom-logo',
    			'itemprop' => 'logo',
    		);
    
    		$image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
    		if ( empty( $image_alt ) ) {
    			$custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
    		}
    		
    	    $html = sprintf( '%2$s',
    			esc_url( 'oceanwp.org' ),
    			wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr )
    		);
    	}
        return $html;   
    }
    add_filter( 'get_custom_logo', 'my_custom_logo_link' );

    Isn’t working for me 🙁

    I tried this to my child theme’s functions.php file..

    function my_custom_logo_link() {
        $custom_logo_id = get_theme_mod( 'custom_logo' );
        if ( $custom_logo_id ) {
    	    $custom_logo_attr = array(
    			'class'    => 'custom-logo',
    			'itemprop' => 'logo',
    		);
    
    		$image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
    		if ( empty( $image_alt ) ) {
    			$custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
    		}
    		
    	    $html = sprintf( '%2$s',
    			esc_url( 'https://www.bohubrihi.com/' ),
    			wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr )
    		);
    	}
        return $html;   
    }
    add_filter( 'get_custom_logo', 'my_custom_logo_link' );
    Theme Author oceanwp

    (@oceanwp)

    Oh sorry, I didn’t notice, I can’t add the right code here, delete this code and add this one: http://docs.oceanwp.org/article/473-change-custom-logo-url

    Thank you <3

    Theme Author oceanwp

    (@oceanwp)

    You’re welcome 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to set custom link for logo’ is closed to new replies.