TinyMCE custom button retrieve value from custom field

Rather than finding the custom field value when the user hits the button, change the [custom field value] to a shortcode name (perhaps “[mkay_subscription_button_value]”?) and then create a shortcode that can replace the value of that key with the post’s custom meta. Something like this: function 246286_display_custom_field( $atts ) { $data = get_post_meta( get_the_ID(), ‘mkay_custom_field’, … Read more

Custom styles in Tiny MCE with an external CSS file

The path to the CSS file tinymce.min.css was incorrect. The solution was to change: $url .= trailingslashit( plugin_dir_url(get_stylesheet_directory_uri()) ) . ‘/tinymce.min.css’; to: $StyleUrl = get_stylesheet_directory_uri().’/style-sheets/tinymce.min.css’; I also had to change: $StyleUrl = plugin_dir_url(get_stylesheet_directory_uri()).’tinymce.min.css’; to: $StyleUrl = get_stylesheet_directory_uri().’/style-sheets/tinymce.min.css’; Now all I had to do was to remove the styles array so the complete code is: // … Read more

WordPress wraps span tags into p tags

I have investigated this problem and recognized that it is not the TinyMCE fault, but the issue is caused by the the hook function wpautop instead. And tags are wrapped just before post is being displayed. So in order to fix this issue just remove the hook function like that. remove_filter( ‘the_content’, ‘wpautop’ ); This … Read more

Stop editor from adding “amp;” after every “&”

One solution is to hook into wp_insert_post_data and do some regex magic to replace all instances of & with &: // when saving posts, replace & with & function cc_wpse_264548_unamp( $data ) { $data[‘post_content’] = preg_replace( “/&/”, // find ‘&’ “&”, // replace with ‘&’ $data[‘post_content’] // target the ‘post_content’ ); return $data; } add_filter( … Read more

How to add custom tinymce plugin to new text widget

I found the solution with help from Jacob Peattie and the article from https://make.wordpress.org/core/2017/05/23/addition-of-tinymce-to-the-text-widget/ Here’s a quick walkthrough on what i did: I made a new js file container the code of my original button, but modified it to the event listener of the widget tinymce jQuery( document ).on( ‘tinymce-editor-setup’, function( event, editor ) { … Read more

How to apply a custom skin to WP_Editor / TinyMCE?

Apparently, the default WordPress style files overwrite a custom TinyMCE skin. So what you need to do is deregister WordPress’s TinyMCE skin. Since I needed the custom skin to only apply on the front-end on my website, I wrapped it inside an !is_admin() conditional. function remove_editor_buttons_style() { // If not on wp-admin if ( !is_admin() … Read more

Show class from css in format dropdown

Array value ‘content_css’ is not enough, TinyMCE can’t simply get the classes from the custom.css file. You need to define the list of styles you want in the dropdown: function my_format_TinyMCE( $in ) { $in[‘content_css’] = get_template_directory_uri() . “/custom.css”; $in[‘importcss_append’] = TRUE; $in[‘style_formats’] = json_encode(array( array(‘title’ => ‘Title for Style #1’, ‘classes’ => ‘example-class’), array(‘title’ … Read more

How to add table class for tables of TinyMCE advanced wordpress plugin? [closed]

Add this code in your theme’s functions.php file //wp-content/themes/my-theme/functions.php function bootstrap_classes_tinymce($settings) { $styles = array( array( ‘title’ => ‘None’, ‘value’ => ” ), array( ‘title’ => ‘Table’, ‘value’ => ‘table’, ), array( ‘title’ => ‘Striped’, ‘value’ => ‘table table-striped table-hover’, ), array( ‘title’ => ‘Bordered’, ‘value’ => ‘table table-bordered table-hover’, ), ); $settings[‘table_class_list’] = json_encode($styles); … Read more

How can a TinyMCE modal return formatted/visual text?

(Revised answer) You can use tinymce.DOM.encode() to convert all HTML tags to their entities, e.g. &lt; for < and &gt; for >: var html = tinymce.DOM.encode(e.data.code); Then to preserve trailing white-spaces: html = html.replace(/(^ +| +$)/gm, function(match, p1){ return p1.replace(/ /g, ‘&nbsp;’); }); And this to convert all line breaks to <br>: html = html.replace(/(?:\r\n|\r|\n)/g, … Read more