Hot answers tagged

195

We will hook into init and remove actions as followed: function disable_wp_emojicons() { // all actions related to emojis remove_action( 'admin_print_styles', 'print_emoji_styles' ); remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( '...


69

To add our button to the TinyMCE editor we need to do several things: Add our button to the toolbar Register a TinyMCE plugin Create that TinyMCE plug-in which tells TinyMCE what to do when our button is clicked. Steps #1 and #2 In these steps we register our TinyMCE plug-in which will live inside a javascript file at 'path/to/shortcode.js' (see ...


49

You can not enhance the drop down list formatselect. But you can enhance with the hook tiny_mce_before_init the second drop down styleselect, there is hide in a default WordPress install. The documentation list all defaults and possibilities. inline – Name of the inline element to produce for example “span”. The current text selection will be wrapped in ...


28

Better solution if you want to disable this: use a plugin. Same code as from Christine's comments: https://wordpress.org/plugins/disable-emojis/ Same code that also fixes the smilies to be the older ones: https://wordpress.org/plugins/classic-smilies/ Source: Me, since I wrote that code in the first place. https://plugins.trac.wordpress.org/changeset/...


24

The following small plugin creates a custom button inside line 1 of the WordPress TinyMCE Version 4, tested in WP Version 3.9-beta2. The plugin has var_dump included to understand the values. It's also possible to add the button to other lines of the visual editor, only a other hook, like for line 2: mce_buttons_2. Result Plugin, PHP side - tinymce4-test....


20

One option is to add a class to the Styleselect menu in MCE. Adapted from the "TinyMCE Custom Styles" Codex page you first need to add the style select to the editor: // Callback function to insert 'styleselect' into the $buttons array function my_mce_buttons_2( $buttons ) { array_unshift( $buttons, 'styleselect' ); return $buttons; } // Register ...


19

If you look in class-wp-editor.php you'll find that the filter you are using is still there, however the settings are different. self::$first_init = array( 'theme' => 'modern', 'skin' => 'lightgray', 'language' => self::$mce_locale, 'formats' => "{ ...


18

Here's a way to test the core patch #33300.6 by Andew Ozz, through a test plugin in WP 4.5.2, to try out the text pattern filter. Demo Here's a strikethrough example using ~ $init['wpsetextpattern_inline_patterns'] = '{ strong: { start: "*", end: "*", format: "bold" }, strong2: { start: "**", end: "**", format: "bold" ...


17

Regardless of what you have configured as valid children, WordPress handles p tags as well as line breaks in a very unique way. You'll probably notice eventually, if you haven't already, that when switching from the text editor to the visual editor and back that your <p> tags get stripped, similar to what occurs on the frontend. A way to block this ...


16

If a function echos data, you can use php output buffering to capture the echoed output and return it instead // Turn on the output buffer ob_start(); // Echo the editor to the buffer wp_editor(); // Store the contents of the buffer in a variable $editor_contents = ob_get_clean(); // Return the content you want to the calling function return $...


16

You can use a {$taxonomy}_edit_form_fields action hook to add html to the term edit table. In that HTML you can remove description textarea and add tinymce editor add_action("{$taxonomy}_edit_form_fields", 'add_form_fields_example', 10, 2); function add_form_fields_example($term, $taxonomy){ ?> <tr valign="top"> <th scope="row"&...


14

Here's a pastebin with your code included. Get the old value of the tinyMCE $meta_biography = get_post_meta( $post->ID, 'meta_biography', true ); Call the TinyMCE Editor wp_editor( $meta_biography, 'biography', array( 'wpautop' => true, 'media_buttons' => false, 'textarea_name' => 'meta_biography', 'textarea_rows' => ...


14

Try this: replace 'theme_advanced_disable' => 'fullscreen' with 'toolbar1'=> 'bold,italic,underline,bullist,numlist,link,unlink,forecolor,undo,redo' Also, remove 'teeny' => true,


14

This is the simple way to remove emoji. Add bellow code to your function.php remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'wp_print_styles', 'print_emoji_styles' );


14

We start by adding the custom TinyMCE Button: function add_mce_button_custom_em() { // check user permissions if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) { return; } // check if WYSIWYG is enabled if ( 'true' == get_user_option( 'rich_editing' ) ) { add_filter( '...


14

The first thing to do is to select the active editor. Here we select the editor using its id, which is content. var activeEditor = tinyMCE.get('content'); Then we use tinyMCE's setContent: var activeEditor = tinyMCE.get('content'); var content = 'HTML or plain text content here...'; activeEditor.setContent(content); However, if the editor is in text mode ...


13

It's always a good idea to look at Wordpress Codex before asking. TinyMCE Custom Styles <?php // Insert 'styleselect' into the $buttons array function my_mce_buttons_2( $buttons ) { array_unshift( $buttons, 'styleselect' ); return $buttons; } // Use 'mce_buttons' for button row #1, mce_buttons_3' for button row #3 add_filter('mce_buttons_2', '...


12

Adding scripts after TinyMCE: You might check out the before_wp_tiny_mce and after_wp_tiny_mcehooks. If you take a look at the file /wp-includes/class-wp-editor.php you can see that the TinyMCE settings scripts are not all loaded through the usual enqueue methods, but some are displayed via: add_action( 'admin_print_footer_scripts', array( __CLASS__, '...


12

I had a lot of trouble finding information and examples of this, so here you go: https://github.com/dtbaker/wordpress-mce-view-and-shortcode-editor This converts a [shortcode] into a nice custom view to match the frontend, and adds an edit button for easy shortcode editing. <?php /** * Class dtbaker_Shortcode_Banner * handles the creation of [...


11

Ok, this was driving me nuts too as it seems to be completely undocumented However, fear not for it is surprisingly easy to fix! :D In your tiny_mce_before_init hook function right before the return statement simply add the line: unset($init['preview_styles']); This will make wordpress function as it did before the 3.6 update (the updated added a line in ...


11

So I'm answering my own question, for those that face or will face the same problem. I have added two buttons. One opens wordpress' build-in window to select a post and inserts the link. The other opens wordpress' build-in media window to select an image. That is what somehow what you get at the end. You will need two PHP functions and one JS one in a ...


10

There is a hook for that: 'mce_css'. It is called in _WP_Editors::editor_settings() and you get all loaded stylesheets comma separated as the first and only parameter. Now it is easy: Use the global variable $editor_styles (here are your theme’s and parent theme’s editor stylesheets stored already), add the time of the file’s last modification as a ...


10

The answer suggested by GavinR is correct. You don't need to install the suggested plug-in, though. Just add this mini plugin and you're set: <?php defined( 'ABSPATH' ) OR exit; /* Plugin Name: TinyMCE break instead of paragraph */ function mytheme_tinymce_settings( $tinymce_init_settings ) { $tinymce_init_settings['forced_root_block'] = false; ...


10

WordPress provides a mce_css filter, that can be used to add custom stylesheets to the Visual Editor. According to the Codex: The file can be a .php file, allowing dynamic generation of CSS rules for the content editor. Example Codex filter callback, modified for a Theme: function wpse120831_mce_css( $mce_css ) { if ( ! empty( $mce_css ) ) ...


10

That is a very good question. I just tested your code locally and see the same result. A little digging reveals a twp-part problem. wp-includes/class-wp-editor.php is a good read for TinyMCE customizations WordPress 3.9 did update to TinyMCE 4.0 and the TinyMCE docs imply that the superscript button is now called "superscript" and not just "...


9

I couldn't get toscho's answer to work for the current version of WordPress (4.7.2), and that seems to be because the TinyMCE init array has a cache_suffix set to 'wp-mce-' . $tinymce_version. So instead, you can just overwrite that with the tiny_mce_before_init filter, like so: function wpse33318_tiny_mce_before_init( $mce_init ) { $mce_init['...


9

You can filter the TinyMCE body classes to add or change as needed. It's a string that's pre-populated with some things like post type, so the easiest thing to do is append your additional classes (with a preceding space). <?php function wpse_128380_tinymce_body_class( $mce ) { // you could do things here to detect whatever you need // and use ...


8

It should be 'media_buttons' => FALSE. array ( 'textarea_rows' => 5, 'media_buttons' => FALSE, 'teeny' => TRUE, 'tinymce' => TRUE ) … creates this editor:


8

In extended toolbar view (Alt+Shift+Z), Pressing the "indent" button to a list or part of list would be make it one step more deeper


8

Background This issue revolves around the removal of empty <span></span> elements in TinyMCE when saving a post or switching between between the Visual and Text editor tabs. The problem is inherent to core functionality (as of trunk version 4.0-alpha-20140602) and is unchangeable via the standard WordPress APIs, as is mentioned in ticket #26986. ...


Only top voted, non community-wiki answers of a minimum length are eligible