Need some help with this one, as logo is working with dynamic data selected.
Now need to be able to change the wordpress favicon easily
This is how I’m currently doing it to update favicon as well as the sites name, using two fields on an acf options pages:
add_action('acf/save_post', 'update_site_identity');
function update_site_identity() {
update_option('site_icon',get_field('favicon','options', false), true);
update_option('blogname', get_field('site_title', 'options'), true);
}
1 Like
thanks for the response, but this is not working for my
Then maybe post some screenshots of your fields, options page, code, etc…
Hey Casper,
you can use WordPress’ get_site_icon_url hook.
add_filter( 'get_site_icon_url', function( $url ) {
// Get the custom site icon from an options page
$custom_site_icon = get_field( 'custom_site_icon', 'option' );
if ( ! empty( $custom_site_icon ) ) {
if ( is_array( $custom_site_icon ) ) {
// return type: Image Array
return $custom_site_icon['url'];
} else if ( is_int( $custom_site_icon ) ) {
// return type: Image ID
return wp_get_attachment_image_url( $custom_site_icon );
} else {
// return type: Image URL
return $custom_site_icon;
}
}
return $url;
} );
Let me know if that helps.
Tried this code as well, and not working…
thanks guys
Hey Casper,
it would help a lot if you could show some actual code. Then we‘re happy to help.
Best,
André
Here is the code to create the options page
<?php
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme General Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
created an image field with custom_site_icon as the field name, and tried your code
Let me know if I should create a admin login for you