wpsmith / genesis-sandbox-featured-content-widget

Genesis Sandbox Featured Content Widget. Based on Nick Croft's Genesis Featured Widget Amplified for additional functionality which allows support for custom post types, taxonomies, and extends the flexibility of the widget via action hooks to allow the elements to be re-positioned or other elements to be added.
39 stars 21 forks source link

Returns Post Image ("a" tag) When None Exists #45

Open MadSpaniard opened 9 years ago

MadSpaniard commented 9 years ago

(Note: previously posted this in the WP plugin page, then I realized this Git exists...)

In the case where the widget is set up to "show featured image", it seems the plugin is always returning a post image (wrapped in "a" tag) even when there is none defined on the post. This causes the plugin to insert an empty "a" html element in the returned code (i.e. without an img element within the anchor element), even though there is no featured image. This can be a problem because if there is margin/padding (on a.alignleft, for example), then the post title ends up getting displaced to accommodate the empty anchor.

The issue seems to be on lines 390-393 of "widget.php".

Specifically, it exits if "show_image" is not set:

//* Bail if empty show param
if ( empty( $instance['show_image'] ) ) {
   return;
}

Maybe this could be fixed by also checking whether an image exists and exiting if there is no image, for example something like this:

//* Bail if empty show param OR if no image exists
if ( empty( $instance['show_image'] ) || ! genesis_get_image () ) {
   return;
}

By checking for both "show_image" and "if there is an image", it will prevent the generation of the extra "a" element further down in the code.

I hope this helps.