0

I need to create an image widget which is similar to the wordpress media image widget, defined in the wordpress core in wp-includes/widgets/class-wp-widget-media-image.php. I only need a couple minor differences:

  • Remove the inline style which is hard-coded into the $image_attributes array as 'style' => 'max-width: 100%; height: auto;',
  • No title should appear on the front end even if one is entered on the backend.

I searched for filter hooks that would allow me to set these widget properties but found nothing useful. I even tried copying the source code for the WordPress image widget and modifying to create the desired widget. However, I was not able to change the frontend title output. Can anyone describe the correct way to go about creating this widget?

1 Answer 1

0

There seems to be no official hooks that effect media widgets. It is possible to access the properties of the widgets in the sidebar using the dynamic_sidebar_params hook in combination the $wp_registered_widgets global widget array. However, there is no image widget property for setting the inline styling of the image.

Therefore the simplest solution to make these two minor changes to the image widget is to use css rules:

... .widgettitle {
    display: none
}
... img {
    height 44px !important;
}

If css rules were not an option then the best solution would be to use output buffering, as descriped in https://stackoverflow.com/questions/1385954/do-wordpress-widget-or-sidebar-hooks-exist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.