Favicon from Custom Field on Settings Page

Support General Favicon from Custom Field on Settings PageResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #42680
    UnakritiUnakriti
    Participant

    Hello,

    I have a Settings page with a 'image advanced' custom field meant to set the favicon. I followed your guide/s at post 1 and post 2 to create the following code. But its not working.

    <?php 
    function prefix_dynamic_favicon(){
    
       $favicon = rwmb_meta( 'favicon', [ 'object_type' => 'setting' ], 'site-identity' );
       $favicon = $favicon ? $favicon['url'] : get_site_icon_url();
    
       echo "<link rel='shortcut icon' href='$favicon' sizes='32x32' type='image/x-icon'>";
    }
    add_action( 'wp_head', 'prefix_dynamic_favicon' );

    Could you please advise a solution here to set the site's favicon using an MB custom field on a settings page?

    Kind regards,

    #42697
    PeterPeter
    Moderator

    Hello,

    Following the guide, you should use the field type single_image. If you want to use the field image_advanced, you can use the function reset() to get the first-one image. For example:

    $favicon = rwmb_meta( 'favicon', [ 'object_type' => 'setting' ], 'site-identity' );
    $favicon = reset( $favicon );

    Read more in the documentation https://docs.metabox.io/fields/image-advanced/

    #42730
    UnakritiUnakriti
    Participant

    Thank you Peter.

    The moment I switched to the single_image field, it started working as expected.

    Apprecaite your support.

    Kind regards,

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.