Guest User

Untitled

a guest
Oct 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. tinyMCEPopup.onInit.add( function() {
  2. if ( ! tinyMCEPopup.editor.dom.getParent( tinyMCEPopup.editor.selection.getNode(), 'A' ) ) {
  3. selectByValue( document.forms[0], 'target_list', '_blank' );
  4. }
  5. } );
  6.  
  7. <?php
  8. /*
  9. Plugin Name: WPSE 7785
  10. Plugin URI: http://wordpress.stackexchange.com/questions/7785/is-there-any-way-to-set-default-for-insertedit-link-to-open-link-in-new-window--
  11. Description: Is there any way to set default for "Insert/Edit Link" to "Open link in new window"?
  12. Version: 1.0
  13. Author: Jan Fabry
  14. */
  15. add_filter( 'tiny_mce_before_init', 'wpse7785_tiny_mce_before_init' );
  16. function wpse7785_tiny_mce_before_init( $initArray )
  17. {
  18. $initArray['external_link_list_url'] = plugins_url( 'wpse-7785.js', __FILE__ );
  19. return $initArray;
  20. }
  21.  
  22. /*
  23. * Sets "Open link in a new window/tab" to checked by default
  24. */
  25. function ahu_after_wp_tiny_mce() {
  26. ?>
  27. <script type="text/javascript">
  28. jQuery( function() {
  29. jQuery( 'input#link-target-checkbox' ).prop( 'checked', true );
  30. } );
  31. </script>
  32. <?php
  33. }
  34. add_action( 'after_wp_tiny_mce', 'ahu_after_wp_tiny_mce' );
  35.  
  36. <?php
  37. /*
  38.  
  39. Plugin Name: Default New Window Link Opener
  40. Plugin URI: https://github.com/eballo
  41. Description: Plugin for wordpress that allow you to enable the check in the popup "Insert/Edit Link” to open a link in new window by default
  42. Version: 1.0
  43. Author: eballo
  44.  
  45. This plugin is based on the solution made by Jan Fabry and lewayotte in wordpress stackexchange forum.
  46.  
  47. http://wordpress.stackexchange.com/questions/7785/is-there-any-way-to-set-default-for-insert-edit-link-to-open-link-in-new-wind
  48.  
  49. */
  50.  
  51. /**
  52. * Sets "Open link in a new window/tab" to checked by default
  53. */
  54. function wplink_tiny_mce_init()
  55. {
  56. ?>
  57. <script type="text/javascript">
  58. jQuery(function () {
  59. jQuery('input#wp-link-target').prop('checked',true);
  60. });
  61. </script>
  62. <?php
  63. }
  64.  
  65. add_action( 'before_wp_tiny_mce', 'wplink_tiny_mce_init' );
  66.  
  67. ?>
  68.  
  69. function edit_tag_link_new_window($content) {
  70. $content = preg_replace('/href/', 'target="_blank" href', $content);
  71. return $content;
  72. }
  73. add_filter('edit_tag_link', 'edit_tag_link_new_window');
  74.  
  75. <input type="checkbox" id="link-target-checkbox" tabindex="30" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
  76.  
  77. <input type="checkbox" id="link-target-checkbox" checked tabindex="30" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
Add Comment
Please, Sign In to add comment