Created
February 28, 2017 20:28
-
-
Save wp-kitten/c647cda5ddacc5b27f1db20a3a476ae2 to your computer and use it in GitHub Desktop.
Add WordPress Internal Link Popup
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
/* | |
* Load the scripts needed so we can display the Internal Link Popup | |
*/ | |
add_action( 'admin_enqueue_scripts', 'loadScripts', 800 ); | |
function loadScripts( $hook ) { | |
if( is_admin()) { | |
wp_enqueue_script( 'wplink' ); | |
wp_enqueue_style( 'editor-buttons' ); | |
} | |
} | |
/* | |
* Include the javascript and PHP file needed to display the Internal Link Popup | |
*/ | |
add_action( 'admin_footer', 'adminFooterScripts' ); | |
function adminFooterScripts() { | |
if( is_admin()) | |
{ | |
// Require the core editor class so we can call wp_link_dialog function to print the HTML. | |
// Luckily it is public static method, so no need to have a hidden wp-editor | |
require_once( trailingslashit( ABSPATH ) . "wp-includes/class-wp-editor.php" ); | |
_WP_Editors::wp_link_dialog(); ?> | |
<script type="text/javascript"> | |
/* We need ajaxurl to send ajax to retrive links. This script can also be localized */ | |
var ajaxurl = "<?php echo admin_url( 'admin-ajax.php'); ?>"; | |
jQuery(function ($){ | |
/* THE_ID_OF_THE_ELEMENT_CLICKED => usually a text area or input text */ | |
$('#THE_ID_OF_THE_ELEMENT_CLICKED').click(function (){ | |
wpLink.open('THE_ID_OF_THE_ELEMENT_CLICKED'); /* Bind to open the link editor */ | |
}); | |
}) | |
</script><?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment