Support

Account

Home Forums General Issues How can I set a default image for an image field?

Solved

How can I set a default image for an image field?

  • Hi,

    I have a few image fields to display some vendor logos on my frontend, and these are almost always the same, but for some posts the vendors can be different. That’s why I have set them up as image fields in which I have the ability to change the vendor logos per-post if necessary.

    However every time I make a new post it’s a little cumbersome selecting each vendor logo again to put into the image field. Is there a way I can specify that “this image field is supposed to be X vendor unless I clear the field and specify otherwise”?

    Thank you!

  • I am not sure you can set a default image.

    I think that your template should take care of this for you. I would just setup ACF option with the default image (or define a variable in your template if it’s not something that your client needs to change).

    When you are displaying the logo, you can do something like this:

    
    if ( '' === get_field( 'logo' )  {
      $image_url = get_field( 'default_image', 'option' );
      // Render the default image.
    }
    

    Non option version:

    
    $default_image = (your default image URI);
    if ( '' === get_field( 'logo' )  {
      // Render the default image using $default_image
    }
    
  • You can set the default image ID by setting $field['default_value'] in an acf/prepare_field filter.

    You can add a setting field to image fields to do this but this will not completely work because the script that displays images is not loaded on the ACF field group editor page. At one time someone had posted code for how to load the script but I can no longer find it.

  • This one has me stumped.

    Uploading an image, via ACF as usual, but I need to create multiple sized versions of that same image.
    I could just use the regular add_image_size but, this means any other image uploaded, also gets created at these sizes which is not what I want (there will be around 100+ post_thumbnails created each time).

    So, my question:
    Using ACF to upload an image, how would I then create multiple sized copies of that image?

  • Hi @miksynder

    Could you not use the file field instead? Then add a field for each image size you require?

    Perhaps not ideal but a possible solution

  • Ok I will do like this. Thanks for your guidance.

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

You must be logged in to reply to this topic.