How to Update: Automatically create media_buttons for shortcode selection

You are here: Home » Blog » CMS » WordPress » How to Update: Automatically create media_buttons for shortcode selection

How to Update: Automatically create media_buttons for shortcode selection

How to Update: Automatically create media_buttons for shortcode selection :

Adding this snippet to the functions.php of your WordPress theme will add a select menu with an automatically generated list of your shortcode (s).

  • 1.) You don’t need to add shortcode, the snippet will generate the list for you.
  • 2.) You will notice the comment “enter names of shortcode to exclude bellow” this will let you exclude any shortcodes you don’t want clients to see.
  • 3.) Fixed the pesky JavaScript issue that would only let you add shortcode when using the HTML editor.

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 '&nbsp;<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>';
}

Related Posts:

What is a shortcode in WordPress?

Create a PayPal Donation Shortcode – WordPress

WordPress, SEO, and Social Media Marketing

How do I start a WordPress blog? (hosting wordpress)

What is a Blog?

Show Popular Posts Without Plugins

Allow Contributors to Upload Images in WordPress

What is a Shortcode in WordPress?

Choose your preferred blog CMS platform

WordPress Posts vs Pages

Disable Search in WordPress

How do I create money online using WordPress?

Should I Choose a Hosted or Non-hosted Blogging Platform?

Disable the Admin Bar in WordPress

Using the Current Year in Your Posts – WordPress

FAQ Hacked WordPress Website

Redirect New Registered Users to a Specific Page – WordPress

WordPress by the Numbers Facts

By |2019-02-08T19:25:13-05:00March 20th, 2018|Categories: CMS, WordPress|Tags: , , , , |

About the Author:

I am a loving father, & husband. I am a computer enthusiast. I have used and enjoyed computers since I was young and I enjoy teaching young minds how to code, because it teaches them how to think. Today with YouTube, and social media garbage our youth are losing the ability to think on their own and solve problems. I believe this is a serious epidemic as kids today dont understand that technology is a tool. This tool is being abused, and its underlying effects are taking its toll on kids behaviour, and learning.