The logo is a theme mod, so you can set it with set_theme_mod( 'custom_logo', $value );
, but the value needs to be an attachment ID, so you’ll need to upload it first.
If you don’t want to upload anything, you can use the get_custom_logo()
filter to provide your own HTML for the logo. If you want to mimic the way WordPress does it, just make sure to include the link custom-logo
classes:
function wpse_304465_custom_logo( $html ) {
if ( $html == '' ) {
$html = sprintf(
'<a href="https://wordpress.stackexchange.com/questions/304465/%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
esc_url( home_url( "https://wordpress.stackexchange.com/" ) ),
'<img src="http://www.example.com/myimage.png" class="custom-logo" itemprop="logo">'
);
}
return $html;
}
add_filter( 'get_custom_logo', 'wpse_304465_custom_logo' );