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!
2 Answers
Reset to default 0in 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('/'));
}
?>">