Add custom media_buttons for shortcode selection

I was looking for a simple way to create a menu for my shortcode items and although you can create tinymce plugins I found it to be a pain. So I decided to create a simplified select menu that would require me to change a little HTML to add new items. Adding this wordpress snippet to the functions.php of your wordpress theme will add a new select menu beside the add media icon. Edit the value= to change the inserted text.

This snippet has been recently updated ( shortcode selection ).

 

 

add_action('media_buttons','add_sc_select',11);
function add_sc_select(){
echo '&nbsp;<select id="sc_select">
<option>Shortcode</option>
<option value="[html][/html]">[html]</option>
<option value="[css][/css]">[css]</option>
<option value="[javascript][/javascript]">[javascript]</option>
</select>';
}
add_action('admin_head', 'button_js');
function button_js() {
echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
$("#sc_select").change(function() {$("#content").val($("#content").val()+$("#sc_select :selected").val());})
});
</script>';
}

Be Sociable, Share!

Leave a comment