Last active
August 9, 2016 18:03
-
-
Save AramZS/418faa75b8c74f0241022e5237fa0e9c to your computer and use it in GitHub Desktop.
Filter TinyMCE config to make new pastes default to have links open in new window.
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 format_tiny_mce_pasted_links_with_blank_targets( $in ) { | |
$in['paste_preprocess'] = "function(plugin, args) { | |
var temp = document.createElement('div'); | |
temp.setAttribute('id', 'temp'); | |
temp.innerHTML = args.content; | |
var linkList = temp.getElementsByTagName('a'); | |
for(var i = 0; i < linkList.length; i++){ | |
if (undefined != linkList[i]){ | |
linkList[i].setAttribute('target', '_blank'); | |
} else { | |
break; | |
} | |
} | |
args.content = temp.innerHTML; | |
}"; | |
return $in; | |
} | |
add_filter( 'tiny_mce_before_init', 'format_tiny_mce_pasted_links_with_blank_targets' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment