Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6858637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:11:04+00:00 2026-05-27T02:11:04+00:00

I needed to add the h1, h2, h3 tags to key bindings for ckeditor

  • 0

I needed to add the h1, h2, h3 tags to key bindings for ckeditor and I found this simple function to do this.
This function works fine and as expected, But I can only use it once, If I copy the same function to another directory and try to include it, it doesnt work. What am i doing wrong?

Location: plugins/button-h1/plugin.js

 var a= {
    exec:function(editor){
    var format = {
    element : "h1"
    };
    var style = new CKEDITOR.style(format);
        style.apply(editor.document);
    }
},

// Add the plugin
b="button-h1";
CKEDITOR.plugins.add(b,{
    init:function(editor){
    editor.addCommand(b,a);
    editor.ui.addButton("button-h1",{
    label:"Button H1",
    icon: this.path + "button-h1.png",
    command:b
    });
}
});

But When I create another plugin inside another folder named ‘button-h2’, With the same code but different names and tags, It doesnt work.

Location: plugins/button-h2/plugin.js

// Exactly the same as above, but with "h2" tags.
var a= {
    exec:function(editor){
    var format = {
    element : "h2"
    };
    var style = new CKEDITOR.style(format);
        style.apply(editor.document);
    }
},

// Add the plugin
b="button-h2";
CKEDITOR.plugins.add(b,{
    init:function(editor){
    editor.addCommand(b,a);
    editor.ui.addButton("button-h2",{
    label:"Button H2",
    icon: this.path + "button-h2.png",
    command:b
    });
}
});

Basically, I need a user to be able to use “CTRL + 1” to add heading tags around selected text.
This method works, except I can only use it for one of the headings only, either H1 or H2, not both or more.

In my config.js, I have the following to set everything up.

config.extraPlugins = "button-h1,button-h2";
config.keystrokes =
[
    [ CKEDITOR.CTRL + 49 /*1*/, 'button-h1' ],
    [ CKEDITOR.CTRL + 50 /*2*/, 'button-h2' ]

];

So,
– The Plugin Works, but I can only use it on H1 or H2, NOT BOTH, WHY?
Do I need to put this within a function or something so it can be executed more then once at the same time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:11:05+00:00Added an answer on May 27, 2026 at 2:11 am

    I found the answer for this. I needed to wrap this in a anonymous function.

    (function(){
    var a= 
    {
        exec:function(editor){
            var format = {
            element : "h1"
            };
        var style = new CKEDITOR.style(format);
        style.apply(editor.document);
        }
    },
    
    b="tags-h1";
    CKEDITOR.plugins.add(b,{
        init:function(editor){
        editor.addCommand(b,a);
        editor.ui.addButton(b,{
        label:"Heading 1",
        icon: this.path + "heading-1.png",
        command:b
        });
        }
    });
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I needed to add drag & drop functionality to a Silverlight application. Can
I inherited this Powerbuilder 12.0 project. We needed to add another datawindow (which is
i have this problem: user can add an HTML description and it will be
So I needed to add a user to a database but when I go
Scenario: I needed to add HttpUtility to my project, and I started by adding
In one of my previous apps I needed to add controls to a flowlayoutpanel
I am attemping to use NetUseAdd to add a share that is needed by
Needed Finfo but deleted msi package, so uninstalled php 5.3.0, downloaded 5.3.2 and installed.
I needed to store various strings in a map but I wanted to keep
I can't understand how to solve this. I'm trying to insert my search form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.