I’m using Astra theme on WordPress and I’m trying to replace the site logo with an ACF field entry. Having really big difficulties setting the logo at all using Astra’s astra_replace_header_logo filter. Trying to start with baby steps and replace the logo with a hardcoded url or attachment ID, but neither seem to be working.
function custom_astra_replace_header_logo($image) {
$custom_logo_nav_id = get_field('logo_nav', 'options', false);
if($custom_logo_nav_id) {
$image[0] = '/wp-content/uploads/2021/05/new-logo.png';
return $image;
}
}
add_filter( 'astra_replace_header_logo', 'custom_astra_replace_header_logo' );
This doesn’t seem to have any effect all. I also tried using the attachment ID together with the size. Astra’s function suggests returning url should be fine though (https://github.com/brainstormforce/astra/blob/master/inc/extras.php#L260).
Interesingly if I set the $image to be something odd, like just the attachment ID $image = 5412 ;
I get a broken image on front-end with src(unknown)
Really don’t understand why this isn’t working. Anyone have any experience with this? Any help greatly appreciated, thanks.
2
Answers
Figured out what was wrong. Plugin called WP Offload Media which I use to upload media files to AWS automatically, was for some reason rewriting the URL for the logo and it was always using the original Astra site logo. Even though the function was working. The function works as expected when I disabled Offload Media. Now just need to figure out why that is doing what it's doing :) This was the function I used in the end:
According to the source for that function, it ultimately calls
wp_get_attachment_image_src
The function returns false other failure, or an array of: