Skip to content

Instantly share code, notes, and snippets.

@damianwajer
Last active August 29, 2015 14:08
Show Gist options
  • Save damianwajer/578995540ea252e1920e to your computer and use it in GitHub Desktop.
Save damianwajer/578995540ea252e1920e to your computer and use it in GitHub Desktop.
[WordPress] Add Shortcode Select to WP Editor
<?php
/*
* Add Shortcode Select to WP Editor
*/
function custom_shortcode_select() {
// display shortcode select only on edit screen
$screen = get_current_screen();
if ( $screen != null && ( $screen->base == 'post' || $screen->base == 'edit-tags' ) ) {
echo '<select id="shortcode-select">
<option value="">' . __( 'Add Shortcode' ) . '</option>
<option value="' . esc_attr( '[shortcode option=""]' ) . '" title="' . __( 'Description' ) . '">Shortcode 1</option>
<option value="' . esc_attr( '[shortcode][/shortcode]' ) . '" title="' . __( 'Description' ) . '">Shortcode 2</option>
</select>';
echo '
<script type="text/javascript">
jQuery( document ).ready( function ( $ ) {
$( "#shortcode-select" ).on( "change", function () {
var $this = $( this );
send_to_editor( $this.children( "option:selected" ).val() );
$this.val( "" );
return false;
});
});
</script>';
}
}
add_action( 'media_buttons', 'custom_shortcode_select', 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment