Created
June 4, 2012 09:33
-
-
Save antoniofrignani/2867436 to your computer and use it in GitHub Desktop.
[WP] - Update: Automatically create media_buttons for shortcode selection
This file contains hidden or 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
// http://wpsnipp.com/index.php/functions-php/update-automatically-create-media_buttons-for-shortcode-selection/ | |
add_action('media_buttons','add_sc_select',11); | |
function add_sc_select(){ | |
global $shortcode_tags; | |
/* ------------------------------------- */ | |
/* enter names of shortcode to exclude bellow */ | |
/* ------------------------------------- */ | |
$exclude = array("wp_caption", "embed"); | |
echo ' <select id="sc_select"><option>Shortcode</option>'; | |
foreach ($shortcode_tags as $key => $val){ | |
if(!in_array($key,$exclude)){ | |
$shortcodes_list .= '<option value="['.$key.'][/'.$key.']">'.$key.'</option>'; | |
} | |
} | |
echo $shortcodes_list; | |
echo '</select>'; | |
} | |
add_action('admin_head', 'button_js'); | |
function button_js() { | |
echo '<script type="text/javascript"> | |
jQuery(document).ready(function(){ | |
jQuery("#sc_select").change(function() { | |
send_to_editor(jQuery("#sc_select :selected").val()); | |
return false; | |
}); | |
}); | |
</script>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment