Home Forums General Issues Write an ACF Image to the WP Site Logo and Site Icon


Write an ACF Image to the WP Site Logo and Site Icon

  • I’m building a “site customizer” page with various site settings easily accessible and editable from a single area (also to be accessed by Editors, in addition to full admins)

    I’ve got simple text things such as the Site Tile, Tagline and even Timezone figured out by using update_options.

    // Update WP Site Options
    update_option('blogname', get_field('platform_title', 'options'), true); // Write custom Site Title
    update_option('blogdescription', get_field('platform_subtitle', 'options'), true); // Write custom site Sub-Title Tagline
    update_option('timezone_string',get_field('platform_timezone','options'), true); // Write custom timezone 
    update_option('custom_logo',get_field('platform_logo','options'), true); // Update Site Logo
    update_option('site_icon',get_field('platform_favicon','options'), true); // Update Site Favicon / Icon

    I know the “update_option” function written like above probably isn’t correct for images. I’m just not sure if/how to write an ACF image field into the WP Logo and Icon fields.

  • These options store ID values, you just need to get the ID value from the ACF field, this can be done by not getting the formatted value using false for the 3rd argument of get_field()

    update_option('custom_logo',get_field('platform_logo','options', false), true); // Update Site Logo
    update_option('site_icon',get_field('platform_favicon','options', false), true); // Update Site Favicon / Icon
  • Quick addendum to this thread because I used it today to update the site_icon. It seems the custom_logo is set by using theme_mod, not update_option (did not work for me).

    The complete code for updating the website logo should be:
    set_theme_mod('custom_logo',get_field('field_name','options', false), true);

    Hopefully this helps someone.

  • @zwebmann this is because your theme is using theme mods which alters the way values are saved. Theme mods are all stored in a single option as a serialized array. Your theme is probably also using get_theme_mod() to get the value rather then get_option().

  • Ah, that makes sense. For reference, I’m using Hello Elementor theme.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.