Archived topic
Change logo title, alt and url
3 replies · Started by Dan on February 10, 2023
Hi, I'm using these 2 filters to change the logo's link, title and alt.
Is there a more efficient way to do this?
Alswo I see that the href ads a bunch of string to it, can those be removed?
add_filter( 'generate_logo_output','tu_logo_atts', 10, 2 );
function tu_logo_atts( $output, $logo ) {
printf(
'<div class="site-logo">
<a href="%1$s" title="my title" rel="home">
<img class="header-image is-logo-image" src="%3$s" alt="Back to site" title=" site home" />
</a>
</div>',
esc_url( apply_filters( 'generate_logo_href' , home_url( '/' )) ),
esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
esc_url( apply_filters( 'generate_logo', $logo ) )
);
}
add_filter( 'generate_logo_href','generate_custom_logo_href' );
function generate_custom_logo_href()
{
// Enter the URL you want your logo to link to below
return 'https://mysite.com';
}
The a href url looks like this:
<a href="https://mysite.com/?__hstc=51647990.cc4469c32bee7a80da4ef82ecea1f255.1641495277475.1668706996969.1670949202315.31&__hssc=51647990.12.1676054050313&__hsfp=901111203" title="" rel="home">
not sure where those characters are coming from. They show up only when filtering the logo href url.
Thanks!
Dan
Hi there,
you can do it just with the generate_logo_output filter:
add_filter( 'generate_logo_output','tu_logo_atts', 10, 2 );
function tu_logo_atts( $output, $logo ) {
printf(
'<div class="site-logo">
<a href="%1$s" title="my title" rel="home">
<img class="header-image is-logo-image" src="%3$s" alt="Back to site" title=" site home" />
</a>
</div>',
esc_url( apply_filters( 'generate_logo_href' , 'your_link_url_goes_here' ) ),
esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
esc_url( apply_filters( 'generate_logo', $logo ) )
);
}
Note that the change is to this line: esc_url( apply_filters( 'generate_logo_href' , 'your_link_url_goes_here' ) ),
Thanks David!
That works.
Have a nice weekend,
Dan
You're welcome and you too!