Hello to everyone!

I've been wracking my brains, trying to find a solution for this. And here is what I have.


I want to detect in which tag my cursor(caret) is standing, and then to select those tags with the text inside. I've tried to do this using TinyMCE API but to no avail, since I don't quite really understand how it works with Wordpress fully.

The style_formats feature already has what I want to do. It behaves exactly like I want it to be. It changes the styling of the whole block doesn't matter where my cursor is. But I decided not to use it because I want all my styles to be on the same custom button.


For example I have some text between h1 tags <h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1>. For instance, I put my cursor after the word ipsum and in return, I want to get the whole line with the tags.

What I already have:

I already have the code that changes the selected text. But I want also to know how to apply the change to the block of text where my cursor is standing.

(function() {
    tinymce.PluginManager.add('test_tc_button', function( editor, url ) {
        editor.addButton( 'test_tc_button', {
            title: 'test toolbar',
            type: 'menubutton',
            icon: 'icon test-own-icon',
            menu: [

            // Standard Quote Section
                text: 'Quote',
                icon: 'icon custom-icon-quote',
                onclick: function() {                        
                   var selection = '';                       
                   selection = editor.selection.getContent({
                        'format': 'text'    
                   if ( selection.length === 0 ) {
                       alert('No text has been selected!');
                   editor.insertContent('<p class="blockquote">' + selection + '</p>');


Thankful in advance!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.