-
-
Save tommcfarlin/473c83510b0fb96e82e0 to your computer and use it in GitHub Desktop.
[WordPress] Through a combination of the TinyMCE API and the HTML5 mark tag, here's how you can highlight text in the WordPress editor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ed.addCommand( 'highlight', function() { | |
var markOpen = '<mark>', | |
markClose = '</mark>', | |
highlight = markOpen + ed.selection.getContent() + markClose; | |
ed.focus(); | |
ed.selection.setContent( | |
markOpen + ed.selection.getContent() + markClose | |
); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ed.addCommand( 'highlight', function() { | |
var markOpen = '<mark>', | |
markClose = '</mark>', | |
highlight = markOpen + ed.selection.getContent() + markClose; | |
ed.focus(); | |
/* Determine if there is highlighted text. | |
* If so, remove it; otherwise, highlight it. | |
*/ | |
if ( -1 < ed.getContent().indexOf( highlight ) ) { | |
ed.setContent( | |
ed.getContent().replace( highlight, ed.selection.getContent() ) | |
); | |
} else { | |
ed.selection.setContent( | |
markOpen + ed.selection.getContent() + markClose | |
); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'admin_init', 'acme_add_editor_style' ); | |
/** | |
* Adds a stylesheet to provide styling the for WordPress Editor | |
* | |
* @since 1.0.0 | |
*/ | |
function acme_add_editor_style() { | |
add_editor_style( get_template_directory_uri() . '/assets/css/editor-style.css' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment