Skip to main content

How To Add A Custom Button To WordPress Editor

Submitted by admin on Sat, 11/27/2021 - 21:29
WordPress Editor button

In this WordPress tutorial I will explain how to add a new custom quick tag button in WordPress editor.
You can use this method in your theme or plugin to add a new quick tag button in WordPress editor.

Now we are going to a new quick tag button
Add following codes at the bottom of functions.php of your theme or plugin's main php file.


<?php
// Add New Custom Quicktag button
function gelcode_add_quicktags() {
  if (wp_script_is('quicktags')){
    ?>
    <script type="text/javascript">
    QTags.addButton( 'eg_gelcode', 'GelCode', '', '', 'GelCode', 'My New custom Tag', 201 );
    </script>
  <?php
  }
}
add_action( 'admin_print_footer_scripts', 'gelcode_add_quicktags' );
?>

Similarly, you can use this method to add your custom shortcodes buttons in WordPress editor. Like below code will add button for shortcode [box][/box]


<?php
// Add New Custom Quicktag button
function gelcode_add_quicktags() {
  if (wp_script_is('quicktags')) {
    ?>
    <script type="text/javascript">
    QTags.addButton( 'eg_gelcode', 'GelCode', '', '', 'GelCode', 'My New custom Tag', 201 );
    </script>
  <?php
  }
}
add_action( 'admin_print_footer_scripts', 'gelcode_add_quicktags' );
?>

Hope this article helped you.

Category

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.