Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The Jetpack image widget does not offer a target option for links. Is there a way to open all Jetpack image widget links in a new window without hacking the plugin? Like through a hook or function?

share|improve this question

closed as off-topic by birgire, Pieter Goosen, Pat J, G. M., Johannes Pille Sep 28 at 12:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – birgire, Pieter Goosen, Pat J, G. M., Johannes Pille
If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

up vote 1 down vote accepted

There is no hook available in the plugin.

One solution is to simply copy this Jetpack Widget and add the target option.

Another is through jQuery, in the file /theme/functions.php:

add_action( 'wp_enqueue_scripts', 'jetpack_widget_wpse_88067' );

function jetpack_widget_wpse_88067() 
{
    wp_enqueue_script( 
        'jetpack-hack', 
        get_stylesheet_directory_uri() . "/js/jethack.js", 
        array( 'jquery'), // dependencies
        false, // version
        true // in footer
    );
}

And in the file /theme/js/jethack.js:

jQuery(document).ready(function($) {   
    $('.jetpack-image-container a').attr('target','_blank');
});   
share|improve this answer

Another option would be to add this to your home.php

<script type="text/javascript">
jQuery(document).ready( function($) {
  jQuery('.widget_image a').attr('target', '_blank');
});
</script>
share|improve this answer

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