Easily add image fields to your custom widgets.
PCo Image Widget Field allows developers to add multiple image fields to custom widgets.
By calling pco_image_field()
inside your widget’s form() function, you will be able to give your users a way to add images via the WordPress Media Frame.
There are just a few strings to translate. However, it would be great to have more languages available. Please contact us to add your translation to the plugin!
Contribute to this project on github or find all of our favorite and custom made plugins
pco_image_field( $this, $instance );
inside your Widget’s form() method.It’s possible to add settings to the function by adding a settings array as a third argument: array( 'title' => 'your-title', 'update' => 'your-update-text', 'field' => 'your-image-field' )
. Here are what each setting does…
Note that this plugin will not save your widget data or show your image anywhere on the front-end. It will simply store the field inside the $new_instance array and wait for you to save the widget. Once the widget instance is saved, you will be able to retrieve the image id from the widget data.
pco_image_field( $this, $instance );
inside your Widget’s form() method.It’s possible to add settings to the function by adding a settings array as a third argument: array( 'title' => 'your-title', 'update' => 'your-update-text', 'field' => 'your-image-field' )
. Here are what each setting does…
Note that this plugin will not save your widget data or show your image anywhere on the front-end. It will simply store the field inside the $new_instance array and wait for you to save the widget. Once the widget instance is saved, you will be able to retrieve the image id from the widget data.
No. This plugin was build to make the Media Frame more useful.
Older versions of WordPress will have to use thickbox instead. You can use the Widget Image Field plugin instead, but it’s recommended that you update your WordPress installation instead.
No. This plugin just creates the building blocks.
You will have to manually add the function pco_image_field( $this, $instance )
inside your widget.
Sad. Try these alternatives instead: Image Widget or Simple Image Widget
This plugin was build to let developers easily add an image field to their widgets. If you have a developer available this will be an easy task.
Make sure the plugin has been activated. Adding a function that doesn’t exists will produce a PHP warning and kill the script. To prevent these errors you can use a function_exists before calling pco_image_field()
.
You don’t have to define the settings array. The default field is image_id, and is recommended for simplicity.
Define the field in the setting array. For example:
pco_image_field( $this, $instance, array( ‘field’ => ‘my_image_id’ ) );
pco_image_field( $this, $instance, array( ‘field’ => ‘my_next_image_id’ ) );
pco_image_field( $this, $instance, array( ‘field’ => ‘my_last_image_id’ ) );
Save your field inside your widgets update()
.
There is a problem with your widget.
Then you will have to output the image in your theme.
Get the image id from $instance['image_id'];
and use a function like wp get attachment image();
.
Let us know!
Please add a new ticket inside our support forum!
Please add a new ticket inside our support forum and tell us about the feature request you need!
$pco_iwf
– Globalization of the plugin objectpcoiwf_preview_size
– Change the preview size if you’re using wider widgets