Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
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)? –  Johannes Pille Mar 30 '13 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? –  bungeshea Apr 3 '13 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 Apr 15 '13 at 7:36
    
agreed, plus, it's a TinyMCE/JS question not a WordPress question –  Tom J Nowell Apr 15 '13 at 10:58
1  
@kaiser Re: upvotes - looks like we have our fair share of robo-reviewers. –  brasofilo Apr 20 '13 at 3:53
add comment

1 Answer 1

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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