$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>theme development - Change logo url by category and in some pages|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme development - Change logo url by category and in some pages

matteradmin9PV0评论

I'm trying to change the logo url for some categories and pages. In the Theme options there is the possibility to change the logo img for categories and pages, but can't change the logo url. I have tried this code in my child theme function.php file but it is not working:

function change_logo_url_animacao($html) {
    $custom_logo_id = get_theme_mod( 'custom_logo' );
    $url = home_url( 'pimeanimacao', 'relative' );
    if(is_page( array( 6447, 7 ) )){
         $html = sprintf( '<a href="%1$s">%2$s</a>',
            esc_url( $url ),
            wp_get_attachment_image( $custom_logo_id, 'full', false, array(
                'class'    => 'custom-logo',))
                );
    }elseif(is_category( 39 ) || cat_is_ancestor_of( 39, get_query_var( 'cat' ) )){
        $html = sprintf( '<a href="%1$s">%2$s</a>',
            esc_url( $url ),
            wp_get_attachment_image( $custom_logo_id, 'full', false, array(
                'class'    => 'custom-logo',))
                );
    }elseif(in_category( array( 39,25,18,3,24,58 ) )){
        $html = sprintf( '<a href="%1$s">%2$s</a>',
            esc_url( $url ),
            wp_get_attachment_image( $custom_logo_id, 'full', false, array(
                'class'    => 'custom-logo',))
                );
    }
    return $html;
}

add_filter('get_custom_logo','change_logo_url_animacao');

The header I'm using have this code to load the logo:

<div class="contact_logo">
    <?php xxx_show_logo(true, true); ?>
</div>

And the function called here xxx_show_logo in in the file core.theme.php of the framework. Here is the funcion:

if ( !function_exists( 'xxx_show_logo' ) ) {
    function xxx_show_logo($logo_main=true, $logo_fixed=false, $logo_footer=false, $logo_side=false, $logo_text=true, $logo_slogan=true) {
        if ($logo_main===true)      $logo_main   = xxx_storage_get('logo');
        if ($logo_fixed===true)     $logo_fixed  = xxx_storage_get('logo_fixed');
        if ($logo_footer===true)    $logo_footer = xxx_storage_get('logo_footer');
        if ($logo_side===true)      $logo_side   = xxx_storage_get('logo_side');
        if ($logo_text===true)      $logo_text   = xxx_storage_get('logo_text');
        if ($logo_slogan===true)    $logo_slogan = xxx_storage_get('logo_slogan');
        if (empty($logo_main) && empty($logo_fixed) && empty($logo_footer) && empty($logo_side) && empty($logo_text))
             $logo_text = get_bloginfo('name');
        if ($logo_main || $logo_fixed || $logo_footer || $logo_side || $logo_text) {
        ?>
        <div class="logo">
            <a href="<?php echo esc_url(home_url('/')); ?>"><?php
                if (!empty($logo_main)) {
                    $attr = xxx_getimagesize($logo_main);
                    echo '<img src="'.esc_url($logo_main).'" class="logo_main" alt="'.esc_attr__('Image', 'charity-is-hope').'"'.(!empty($attr[3]) ? ' '.trim($attr[3]) : '').'>';
                }
                if (!empty($logo_fixed)) {
                    $attr = xxx_getimagesize($logo_fixed);
                    echo '<img src="'.esc_url($logo_fixed).'" class="logo_fixed" alt="'.esc_attr__('Image', 'charity-is-hope').'"'.(!empty($attr[3]) ? ' '.trim($attr[3]) : '').'>';
                }
                if (!empty($logo_footer)) {
                    $attr = xxx_getimagesize($logo_footer);
                    echo '<img src="'.esc_url($logo_footer).'" class="logo_footer" alt="'.esc_attr__('Image', 'xxx').'"'.(!empty($attr[3]) ? ' '.trim($attr[3]) : '').'>';
                }
                if (!empty($logo_side)) {
                    $attr = xxx_getimagesize($logo_side);
                    echo '<img src="'.esc_url($logo_side).'" class="logo_side" alt="'.esc_attr__('Image', 'xxx').'"'.(!empty($attr[3]) ? ' '.trim($attr[3]) : '').'>';
                }
                echo !empty($logo_text) ? '<div class="logo_text">'.trim($logo_text).'</div>' : '';
                echo !empty($logo_slogan) ? '<br><div class="logo_slogan">' . esc_html($logo_slogan) . '</div>' : '';
            ?></a>
        </div>
        <?php 
        }
    } 
}

Now I need to change this: <a href="<?php echo esc_url(home_url('/')); ?>"> in some categories and pages to this link "site_domain/pimeanimacao". How can I solve it? Thank you in advance for helping me!

I'm trying to change the logo url for some categories and pages. In the Theme options there is the possibility to change the logo img for categories and pages, but can't change the logo url. I have tried this code in my child theme function.php file but it is not working:

function change_logo_url_animacao($html) {
    $custom_logo_id = get_theme_mod( 'custom_logo' );
    $url = home_url( 'pimeanimacao', 'relative' );
    if(is_page( array( 6447, 7 ) )){
         $html = sprintf( '<a href="%1$s">%2$s</a>',
            esc_url( $url ),
            wp_get_attachment_image( $custom_logo_id, 'full', false, array(
                'class'    => 'custom-logo',))
                );
    }elseif(is_category( 39 ) || cat_is_ancestor_of( 39, get_query_var( 'cat' ) )){
        $html = sprintf( '<a href="%1$s">%2$s</a>',
            esc_url( $url ),
            wp_get_attachment_image( $custom_logo_id, 'full', false, array(
                'class'    => 'custom-logo',))
                );
    }elseif(in_category( array( 39,25,18,3,24,58 ) )){
        $html = sprintf( '<a href="%1$s">%2$s</a>',
            esc_url( $url ),
            wp_get_attachment_image( $custom_logo_id, 'full', false, array(
                'class'    => 'custom-logo',))
                );
    }
    return $html;
}

add_filter('get_custom_logo','change_logo_url_animacao');

The header I'm using have this code to load the logo:

<div class="contact_logo">
    <?php xxx_show_logo(true, true); ?>
</div>

And the function called here xxx_show_logo in in the file core.theme.php of the framework. Here is the funcion:

if ( !function_exists( 'xxx_show_logo' ) ) {
    function xxx_show_logo($logo_main=true, $logo_fixed=false, $logo_footer=false, $logo_side=false, $logo_text=true, $logo_slogan=true) {
        if ($logo_main===true)      $logo_main   = xxx_storage_get('logo');
        if ($logo_fixed===true)     $logo_fixed  = xxx_storage_get('logo_fixed');
        if ($logo_footer===true)    $logo_footer = xxx_storage_get('logo_footer');
        if ($logo_side===true)      $logo_side   = xxx_storage_get('logo_side');
        if ($logo_text===true)      $logo_text   = xxx_storage_get('logo_text');
        if ($logo_slogan===true)    $logo_slogan = xxx_storage_get('logo_slogan');
        if (empty($logo_main) && empty($logo_fixed) && empty($logo_footer) && empty($logo_side) && empty($logo_text))
             $logo_text = get_bloginfo('name');
        if ($logo_main || $logo_fixed || $logo_footer || $logo_side || $logo_text) {
        ?>
        <div class="logo">
            <a href="<?php echo esc_url(home_url('/')); ?>"><?php
                if (!empty($logo_main)) {
                    $attr = xxx_getimagesize($logo_main);
                    echo '<img src="'.esc_url($logo_main).'" class="logo_main" alt="'.esc_attr__('Image', 'charity-is-hope').'"'.(!empty($attr[3]) ? ' '.trim($attr[3]) : '').'>';
                }
                if (!empty($logo_fixed)) {
                    $attr = xxx_getimagesize($logo_fixed);
                    echo '<img src="'.esc_url($logo_fixed).'" class="logo_fixed" alt="'.esc_attr__('Image', 'charity-is-hope').'"'.(!empty($attr[3]) ? ' '.trim($attr[3]) : '').'>';
                }
                if (!empty($logo_footer)) {
                    $attr = xxx_getimagesize($logo_footer);
                    echo '<img src="'.esc_url($logo_footer).'" class="logo_footer" alt="'.esc_attr__('Image', 'xxx').'"'.(!empty($attr[3]) ? ' '.trim($attr[3]) : '').'>';
                }
                if (!empty($logo_side)) {
                    $attr = xxx_getimagesize($logo_side);
                    echo '<img src="'.esc_url($logo_side).'" class="logo_side" alt="'.esc_attr__('Image', 'xxx').'"'.(!empty($attr[3]) ? ' '.trim($attr[3]) : '').'>';
                }
                echo !empty($logo_text) ? '<div class="logo_text">'.trim($logo_text).'</div>' : '';
                echo !empty($logo_slogan) ? '<br><div class="logo_slogan">' . esc_html($logo_slogan) . '</div>' : '';
            ?></a>
        </div>
        <?php 
        }
    } 
}

Now I need to change this: <a href="<?php echo esc_url(home_url('/')); ?>"> in some categories and pages to this link "site_domain/pimeanimacao". How can I solve it? Thank you in advance for helping me!

Share Improve this question edited Dec 18, 2018 at 21:57 RiddleMeThis 3,8078 gold badges22 silver badges30 bronze badges asked Dec 18, 2018 at 19:29 Emanuela NardinEmanuela Nardin 31 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 0

in your child theme you need to override the logo function from the parent. copy the function, minus the if ( !function_exists( 'xxx_show_logo' ) ) { part, into your child theme and add your conditionals for setting the url there.

Solved overrinding the xxx_show_logo function in my child theme function.php file like this:

<div class="logo">
            <a href="<?php 
            if (is_page( array( 6447, 7 ) )) {
            echo esc_url(home_url('/pimeanimacao'));
            } elseif (is_category( 39 ) || cat_is_ancestor_of( 39, get_query_var( 'cat' ) )) {
                echo esc_url(home_url('/pimeanimacao'));
            } elseif (in_category( array( 39,25,18,3,24,58 ) )) {
                echo esc_url(home_url('/pimeanimacao'));
            } else {
                echo esc_url(home_url('/'));
            }
            ?>">
Post a comment

comment list (0)

  1. No comments so far