这已经很老了,但对于其他阅读此问题的人来说,不要使用github,因为它不起作用。
<?php
/**
* Plugin Name: Add JQuery Chosen Quickly
* Plugin URI: http://wordpress.stackexchange.com/questions/85824/
* Description: Test/Add chosen to site without adding any files
* Version: 1.0
*/
function enqueue_chosen_jquery() {
wp_register_style( \'chosencss\', \'https://cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.min.css\', false, \'1.1.0\', \'all\' );
wp_register_script( \'chosenjs\', \'https://cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.jquery.min.js\', array( \'jquery\' ), \'1.1.0\', true );
wp_enqueue_style( \'chosencss\' );
wp_enqueue_script( \'chosenjs\' );
}
add_action( \'wp_enqueue_scripts\', \'enqueue_chosen_jquery\' );
// Assuming jQuery is loaded in the head
function chosen_jquery_inline() {
if ( wp_script_is( \'jquery\', \'done\' ) ) { ?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$( ".chzn-select" ).chosen();
});
</script>
<?php }
add_action( \'wp_head\', \'chosen_jquery_inline\', 999 );