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 8542967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:11:35+00:00 2026-06-11T12:11:35+00:00

I am trying to add a dropdown selection and code button to the WordPress

  • 0

I am trying to add a dropdown selection and code button to the WordPress editor in Javascript.

I found this site that has it done already I am just trying to modify the code slightly. You can see what I am talking about here, you can select a language from the dropdown and then click the code button on that site.

http://bililite.com/blog/blogfiles/customeditor.html

jQuery(function ($) {
  edButtons.forEach(function (button, index) {
    if (button.display == 'code') {

      // add language pull down menu
      edButtons[index + 1] = { // insert right after the code button
        html: function (idPrefix) {
          return '<select id="' + idPrefix + 'code_language" data-code-target="' + index + '">' + '<option></option>' + // include a blank option
          '<option>' + languages.join('</option><option>') + '</option>' + '</select>';
        }
      };
    }
  });

  var languages = ['html', 'javascript', 'lisp', 'pdf', 'php', 'vb'];
  $('body').on('change', 'select[data-code-target]', function () {
    var lang = $(this).val();
   // edButtons[$(this).data('code-target')].tagStart = lang ? '<code class="language-' + lang + '" >' : '<code>';
    edButtons[$(this).data('code-target')].tagStart = lang ? '<pre><code data-language="' + lang + '">' : '<pre><code>';
  });
});

This code currently insert code like this is no language is selected from the dropdwon…

<code></code>

And this when a Language is seleected…

<code data-language="php"></code>

All I need to do is wrap this in <pre> the above code here </pre> tags. I can easily add in the opening pre tag in the code above but I am unable to add the closing tag, I could really use some help from someone who knows Javascript better

  • 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-06-11T12:11:36+00:00Added an answer on June 11, 2026 at 12:11 pm

    You should be able to add the closing tags pretty similar to the starting tags. Try this:

    edButtons[$(this).data('code-target')].tagEnd = lang ? '</pre></code>' : '</code>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add some jQuery to a Wordpress site so that when
Trying to setup some validation on the add to cart button for the dropdown
I'm trying to create a dropdown that upon changing the selection from the list
Im trying to add a delay that works on my dropdown menu if the
I am trying to add a dropdown to sort my custom posts. I have
I'm trying to add items to a dropdown list using a List of ListItems,
I'm trying to add extra HTML attributes to some select options in a dropdown
I am trying to add bootstrap drop down button in a column of jqGrid
I am trying add picture boxes dynamically. My code is as PictureBox picture =
I am trying to add a product that requires form fields...however, by creating the

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.