Last active
May 15, 2017 15:13
-
-
Save BhargavBhandari90/6773522ca54a55c56b945ac050383c69 to your computer and use it in GitHub Desktop.
Remove target blank from edit link.
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 | |
// Add this code to theme's functions.php | |
// Remove target blank from edit link. | |
// 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($) { | |
function remove_blank_target() { | |
jQuery( '.rtmedia-list .rtmedia-list-item' ).each( function(){ | |
var target = jQuery( this ).find( '.rtmedia-gallery-item-actions a:first' ).attr( 'target' ); | |
// Checked for the target attribute if it exists or not and is also set to blank. | |
if ( target != 'undefined' ) { | |
// Replace the blank target attribute to self target attribute. | |
jQuery( this ).find( '.rtmedia-gallery-item-actions a:first' ).attr( 'target', '_self' ); | |
} | |
}); | |
} | |
// Function for removing target blank | |
remove_blank_target(); | |
// Remove target blank when new elements are added | |
jQuery('.rtmedia-list').bind("DOMSubtreeModified",function(){ | |
remove_blank_target(); | |
}); | |
}); | |
</script> | |
<?php | |
} | |
} | |
add_action( 'wp_footer', 'rtmedia_wp_footer_add_js_callback' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment