Home>Support>Create image preset or default value in a custom site origin widget?

Create image preset or default value in a custom site origin widget?

Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

I am trying to build an stylable widget that loads with preset or default styling values when introduced to a page. I have been able to utilize default=”” within the form fields to achieve this effect on all buttons and text. But I am trying to establish a background image that will load in initially and allow the user to change the image through the provided fields. Is there a way to set a default image value in my field setting to achieve this functionality? I have provided my attempt below to better demonstrate my goal.

‘fields’ => [
‘image’ => [
‘type’ => ‘media’,
‘label’ => __(‘Image’, ‘widgets-bundle’),
‘choose’ => __(‘Choose image’, ‘widgets-bundle’),
‘update’ => __(‘Set image’, ‘widgets-bundle’),
‘default’ => ‘https://www.mysite.com/wp-content/uploads/2021/05/randomimage_2560x890.jpg’,
‘library’ => ‘image’,
‘fallback’ => true,

],

Thank you!

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 3 years, 11 months ago Alex S
    Hi, I Work Here

    Hi Sean,

    Unfortunately, the Media form field doesn’t currently support defaults. I’ve logged this as a feature request.
    You could optionally replace the media field with a media field with this feature by filtering the siteorigin_widgets_field_registered_class_paths filter. There’s currently no documentation for this filter – this will be corrected shortly – but there’s an example plugin here that will show you how to do this.

    Kind regards,
    Alex

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More