Support

Account

Home Forums General Issues Setting default image url for theme?

Solved

Setting default image url for theme?

  • I’ve built a theme that will be distributed to my customers.

    Upon activation of the theme I’d like to set the default URL for an image that is included with the theme but can be replaced on the options page by the user.

    How can I easily set the default URL for image type inputs upon activation? I have to do this for many images that are included.

    Thanks

  • I think you could just create the post meta data upon activation.. since it’ll have the correct meta key the options image field should recognize it and it’d be set as “default” from the users point of view..

    Altho I’m not sure where the options page saves it’s data.. if its in the wp_options table you’ll need to use set_option

  • This is for the option pages, so not a post per se. It’s the main site logo, so I was assuming I’d need to use an update field and set the URL since it’s inside of the theme/images folder and not in the wp image gallery.

    I was hoping to easily be able to just do something like update_field (logo, url, value) but no luck.

    Looking for some example code on how to accomplish this.

  • Well if you just take a look at where ACF saves the image field for the optionspage you should be able to do a set_option or add_post_meta depending on if it’s in wp_postmeta or wp_options..

    However a different solution you could do is to have an if statement around the output of the logo (this assumes that the return is set to image URL):

    
    <?php
    if(get_field('custom_logo_field', 'options')){
    $image = get_field('custom_logo_field', 'options');
    }else{
    $image = get_bloginfo('template_directory') . 'images/default-logo.png';
    }
    ?>
    <img src="<?php $image; ?>" alt="company name" id="logo" />
    
    
  • Thanks for the help. I’ll try that. Is there any way to update an option field programmatically?

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.