1

I want something like if I select any word in WordPress Visual Editor, it will get replaced with my own text.

Actually Visual Editor is an iFrame. We can do this thing in textarea, but how can we implement this in iFrame (WordPress Visual Editor)?

Any help would be appreciated.

5
  • 4
    How do you want to select the word - as an end-user with the mouse? Where does the replacement text come from (local machine clipboard, database, code)? Commented Mar 30, 2013 at 19:02
  • 1
    Can you post the script that you use for textareas so we can modify it to work with the visual editor?
    – shea
    Commented Apr 3, 2013 at 5:02
  • 3
    I don't understand the upvotes on this one. This question is impossible to understand, the OP doesn't follow up with any sort of details, etc. Close vote as we haven't had an update in the last 14 days, so I see a lack of interest in this one.
    – kaiser
    Commented Apr 15, 2013 at 7:36
  • agreed, plus, it's a TinyMCE/JS question not a WordPress question
    – Tom J Nowell
    Commented Apr 15, 2013 at 10:58
  • 1
    @kaiser Re: upvotes - looks like we have our fair share of robo-reviewers.
    – brasofilo
    Commented Apr 20, 2013 at 3:53

1 Answer 1

4

The visual editor is an TinyMCE implementation. The first way to repace a selected text, is to write a plugin for the TinyMCE.

If you do not want to write a plugin, use the tinyMCE object:

add_action( 'admin_footer', 'tinyNagging' );

function tinyNagging() {

echo '
<script type="text/javascript">
jQuery(document).ready(
function() {
  window.setInterval(
    function(){
      var selectedText = tinyMCE.activeEditor.selection.getContent( {format : "text"} );
      if ( selectedText != "" )
        tinyMCE.activeEditor.selection.setContent( "FooBar" );
    },
    1000
  );
}
);
</script>
';

}

This script checks every second if a text is selected and replace it with 'FooBar'.

Get the selected text with tinyMCE.activeEditor.selection.getContent( {format : 'text'} ); for plain text or {format : 'html'} for the html markup.

Set the new content with tinyMCE.activeEditor.selection.setContent( [YourNewContent] );

See the TinyMCE manpages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.