• I would be more than grateful if you would shade some light on my issue.

    I have built a custom button on WordPress Editor where there are 2 options [Include & Excludes]. If user selects some paragraph and clicks ‘Include’ then a class should be added in the <p> tags which are only selected or highlighted by user (these <p> tags are auto generated in WordPress visual editor) . Similarly, if user selects some other paragraphs and clicks ‘Exclude’ then a class should be added in the <p> tags which are selected or highlighted by user. Below is my effort:

    (function() {
        tinymce.PluginManager.add('sanjog_custom_tinymce_button', function( editor, url ) {
            editor.addButton( 'sanjog_custom_tinymce_button', {
                title: 'Add stylish <li>',
                type: 'menubutton',
                fixedWidth: true,
                icon: 'icon dashicons-menu',
                menu: [
                        {
                            text: 'Includes',
                            onclick: function() {
                                editor.focus();
                                editor.selection.addClass(editor.select('p'), 'myclass');
                            }
                        },
                        {
                            text: 'Excludes',
                            onclick: function() {
                                editor.focus();
                                editor.selection.addClass(editor.select('p'), 'yourclass');
                            }
                        }
                   ]
    
            });
        });
    })();

    Thank you for your time!

    • This topic was modified 8 years, 3 months ago by saurav.rox.
  • The topic ‘Add custom class to the selected tag [auto generated tags] in WordPress’ is closed to new replies.