Last active
December 15, 2015 18:39
-
-
Save robneu/5305057 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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