Shortcode dropdown box in Tinymce is not working in WordPress 3.9? Shortcode dropdown box in Tinymce is not working in WordPress 3.9? wordpress wordpress

Shortcode dropdown box in Tinymce is not working in WordPress 3.9?


In tinymce4 createControl doen't exist anymore.

You will have to create a button and assign text-value pairs as values to that button.Use the onSelect function to do stuff when you choose an elemtn from the dropdow list.

Here is a piece of example code:

var my_options = [];my_options.push({text: "title1", value: "value1"});my_options.push({text: "title2", value: "value2"});my_options.push({text: "title3", value: "value3"});ed.addButton('shortcodes', {    type: 'listbox',    text: 'my_own_decription',    icon: false,    tooltip: 'my_own_decription',    fixedWidth: true,    onselect: function(e)    {        var options = {paragraphs: 1, calldirect: 1};        var text = this.text();        var value = this.value();        console.log("Text choosen:", text);        console.log("Value choosen:", value);        // get selection and range        var selection = ed.selection;        var rng = selection.getRng();        ...        ed.focus();    },    values: my_options,    onPostRender: function()     {        ed.my_control = this; // ui control element    }});


I had the same issue and was searching around the web. The best possible solution I've found was this article.It worked for me like a charm.

(function() {"use strict";     tinymce.create('tinymce.plugins.shortcodes', {        init : function(ed, url) {            ed.addButton( 'shortcodes', {                type: 'listbox',                text: 'My Shortcodes',                icon: false,                onselect: function(e) {                },                 values: [                    {text: 'H1 Title', onclick : function() {                        tinymce.execCommand('mceInsertContent', false, '[h1][/h1]');                    }},                    {text: 'H2 Title', onclick : function() {                        var selected2 = false;                        var content2 = selected2 = tinyMCE.activeEditor.selection.getContent();                        var h2titleclass = prompt("Would you like a custom class?", "");                        if(h2titleclass != ''){                            h2titleclass = ' class= "'+h2titleclass+'"';                        }                        if (selected2 !== '') {                            content2 = '[h2'+h2titleclass+']' + selected2 + '[/h2]';                        } else {                            content2 = '[h2'+h2titleclass+'][/h2]';                        }                        tinymce.execCommand('mceInsertContent', false, content2);                    }},                ]            });             },    });tinymce.PluginManager.add('shortcodes', tinymce.plugins.shortcodes);})()