Skip to content

Instantly share code, notes, and snippets.

@robneu
Last active December 15, 2015 18:39
Show Gist options
  • Save robneu/5305057 to your computer and use it in GitHub Desktop.
Save robneu/5305057 to your computer and use it in GitHub Desktop.
<?php
function example_image_widget_output( $output, $args, $instance, $id_base ) {
$link_open = '';
$link_close = '';
if ( ! empty ( $instance['link'] ) ) {
$target = ( empty( $instance['new_window'] ) ) ? '' : ' target="_blank"';
$link_open = '<a href="' . esc_url( $instance['link'] ) . '"' . $target . '>';
$link_close = '</a>';
}
// Add the image.
if ( ! empty( $instance['image_id'] ) ) {
$image_size = ( empty( $instance['image_size'] ) ) ? 'medium' : $instance['image_size'];
$output .= sprintf( '<p>%s%s%s</p>',
$link_open,
wp_get_attachment_image( $instance['image_id'], $image_size ),
$link_close
);
}
$output = ( empty( $instance['title'] ) ) ? '' : $args['before_title']. $instance['title'] . $args['after_title'];
// Add the text.
if ( ! empty( $instance['text'] ) ) {
$output .= apply_filters( 'the_content', $instance['text'] );
}
// Add a more link.
if ( ! empty( $link_open ) && ! empty( $instance['link_text'] ) ) {
$output .= '<p class="more">' . $link_open . $instance['link_text'] . $link_close . '</p>';
}
return $output;
}
add_filter( 'simple_image_widget_output', 'example_image_widget_output', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment