Skip to content

Instantly share code, notes, and snippets.

@mangesh
Created February 24, 2017 06:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mangesh/e8ef1447869c28fc44f61f43053c8c7d to your computer and use it in GitHub Desktop.
Open edit media in same window.
<?php
// Check if function doest not exists.
if ( ! function_exists( 'rtmedia_wp_footer_add_js_callback' ) ) {
function rtmedia_wp_footer_add_js_callback() {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
// Event will fire when someone click on edit button of media.
jQuery( 'body' ).on( 'click', '.rtmedia-gallery-item-actions a:first',function(){
var target = jQuery( this ).attr( 'target' );
// Checked for the target attribute if it exists or not and is also set to blank.
if ( target != 'undefined' && target == '_blank' ) {
// Replace the blank target attribute to self target attribute.
jQuery( this ).attr( 'target', '_self' );
}
});
});
</script>
<?php
}
}
add_action( 'wp_footer', 'rtmedia_wp_footer_add_js_callback', 10, 1 );
@pranali333
Copy link

It has some issues. Only works for first media.

Improved version is here - https://gist.github.com/BhargavBhandari90/6773522ca54a55c56b945ac050383c69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment