TinyMCE - Add button that changes direction of selected text

Ok, I am going to create website in Urdu(rtl) & English(ltr) language that contain paragraphs like this: <p style="direction:rtl">کیا حال ہے buddy? سب خیریت ہے؟</p> You can see that sentence in not showing correctly. I want to change the direction of English words in sentense. like this: <p style="direction:rtl">کیا حال ہے <bdo dir="ltr">buddy?</bdo> سب خیریت ہے؟</p> You can see more clear differance at JSfiddle. How it is possible? Any idea?
Category: Web

Line Breaks are stripped off when direction property is found

The line breaks are stripped off when the p tag has a dir attribute inserted, to explain further I'll list some examples. Let's say we have 2 lines of text as following <p>Text Paragraph Number One Goes Here</p> <p>Text Paragraph Number Two Goes Here</p> If I want to add line breaks between the two paragraphs it works fine to become like: <p>Text Paragraph Number One Goes Here</p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p>Text Paragraph Number Two Goes Here</p> However if …
Category: Web

Add Button to TinyMCE Custom Menu

I've added a new button with a menu to the TinyMCE visual editor using this tremendously helpful tutorial but would now like to add further items to this menu depending on whether various post types are active in my theme. I think I'm on the right track with addMenuItem and 'context' but can't figure out how to set this up in the correct order. My plugin code: add_action('admin_head', 'nto_add_shortcode_button'); function nto_add_shortcode_button() { global $typenow; // check user permissions if ( …
Category: Web

wp_localize_script with mce_external_plugins in wordpress

I am not sure if it is possible or not. Can i use wp_localize_script with mce_external_plugins filter? I want to send a variable to the tinymce plugin script. For Example: add_filter( "mce_external_plugins", array( &$this, 'add_test_plugin' ) ); public function add_test_plugin( $plugin_array ){ global $pagenow; if( is_admin() && $pagenow == "post.php" || $pagenow == "post-new.php" ){ $plugin_array['mytest'] = plugin_dir_url(__FILE__) . '/js/testing.js'; return $plugin_array; } } I have to send a variable to testing.js? How do i achieve this? Update: this is …
Category: Web

Keyboard shortcuts with TinyMCE custom styles in Wordpress - possible?

I’ve defined some custom styles as directed in the article here, they work splendidly: https://codex.wordpress.org/TinyMCE_Custom_Styles However, I’d like to add keyboard shortcuts for these styles, and I’m unclear how to do that. It seems easy enough for custom defined buttons on the toolbar, but I don’t see any way to define them for the styles in the drop down. I have found this TinyMCE doc, https://www.tiny.cloud/docs/api/tinymce/tinymce.shortcuts, so I know shortcuts are supported, I just don't understand how to map them …
Category: Web

TinyMCE Autoresize

Looking for a way to make the TinyMCE editor always relative to it's content so that the height of the editor changes accordingly to how much text/images it contains. There seem to be plugins for TinyMCE for this already, but I'm not sure on how to apply it for the Wordpress version: http://www.tinymce.com/wiki.php/Plugin:autoresize function init_tinymce_autoresize($initArray){ $initArray['plugins'] = "autoresize"; return $initArray; } add_filter('tiny_mce_before_init', 'init_tinymce_autoresize'); Does not work. Ideas?
Category: Web

Using wp_editor in TinyMCE WindowManager dialog

I'm currently writing a plugin that provides an interface for adding shortcodes, very simple dropdown added to the TinyMCE toolbar which opens a TinyMCE dialog box with text fields etc. This is all working great, the shortcode is created properly and inserted in to the main WP editor. However, I'm trying to set up a field which is a rich text editor in the dialog box but having some trouble getting it to initialise properly. Here's my TinyMCE plugin: 'use …
Category: Web

TinyMCE Editor change underline button behavior - u tag instead of span text-decoration underline

As above. I want to change the WordPress Edtior TinyMCE behavior when I click the underline button I want the TinyMCE to wrap my selection with <u></u> tags. Now, I know that the u tag was deprecated in HTML 4~ but according to W3 it can be used in HTML5 again. Anyways! I need a <u> tag - not a <span>. Is there a way to change the default underline button behavior without any shortcodes or editing core files? Something …
Category: Web

Add Shortcode inline inside Gutenberg block

In the legacy (classic editor) it was possible to add buttons to the editor toolbar via tinymce API, that will add shortcode at cursor. seems like this is not supported anymore from the tinymce FQA and this Gutenberg migration guide Seems like it would be possible with the plugin tinymce advanced but I wonder what is today the best practice to add add a button to a tiny mce button to the the simple text editor of paragraph block. The …
Category: Web

WP Editor Issue in Backend

I am stuck on silly issue of wp_editor function in WordPress backend in custom plugin page. See issue for wp_editor in attached images I have called the wp_editor function like this <?php wp_editor(stripslashes($item['custom_redirect_message']), "custom_redirect_message", array("wpautop" => false,"name" => "custom_redirect_message", "textarea_rows" => 20)); ?> There is also some js error in console in live environment when I click on link button in editor. The link button should not pop out like this. Any help in this highly appreciated. Thanks Edit:- When …
Category: Web

TinyMCE Visual Blocks plugin set Show blocks option for all users

I want the Show blocks feature of the TinyMCE Visual Blocks Plugin to be activated for all users. I can activate the Show blocks feature under the View menu dropdown manually. See picture. This activates it for the current user. How can I activate the feature for all users? Can it be done via the tiny mce before init hook similar to setting visualblocks_default_state ? https://www.tiny.cloud/docs/plugins/visualblocks/ https://codex.wordpress.org/Plugin_API/Filter_Reference/tiny_mce_before_init
Category: Web

TinyMCE Advanced newline problem

I am using TinyMCE Advanced plugin according to qTranslate in a wordpress 3.3 installation. My question is: why does tinymce translate visual editor new line ("enter" key) in a <p> </p> instead of <br/>? Is it possible to change this behavior?
Category: Web

TinyMce in WordPress - Getting the "fullscreen" button to stay on the right when customising button layout

I'm using TinyMce inside WordPress and I have customised the button layout like so: add_filter( 'tiny_mce_before_init', 'blm_format_tiny_mce' ); add_filter( 'mce_buttons', 'blm_extended_editor_mce_buttons', 0 ); add_filter( 'mce_buttons_2', 'blm_extended_editor_mce_buttons_2', 0 ); function blm_format_tiny_mce( $in ) { $in['remove_linebreaks'] = true; $in['convert_newlines_to_brs'] = false; $in['keep_styles'] = true; $in['tabfocus_elements'] = 'publish'; $in['paste_remove_styles'] = false; $in['paste_remove_spans'] = true; $in['paste_strip_class_attributes'] = 'mso'; $in['paste_text_linebreaktype'] = 'combined'; $in['plugins'] = 'tabfocus,paste,textcolor,lists,fullscreen,wordpress,image,wpeditimage,wpgallery,wplink,wpdialogs'; //$in['valid_children'] = '+div[p]'; return $in; } // TinyMCE: First line toolbar customizations function blm_extended_editor_mce_buttons($buttons) { // The settings are returned …
Category: Web

Customising the WordPress TinyMce editor and it's buttons

I'm trying to cutomise the TinyMce editor within WordPress and I took this code from an older WP site I did, but the buttons I have set don't seem to be working, for example, this is what I have: add_filter( 'tiny_mce_before_init', 'blm_format_tiny_mce' ); function blm_format_tiny_mce( $in ) { $in['remove_linebreaks'] = true; $in['convert_newlines_to_brs'] = false; $in['keep_styles'] = true; $in['tabfocus_elements'] = 'major-publishing-actions'; $in['paste_remove_styles'] = false; $in['paste_remove_spans'] = true; $in['paste_strip_class_attributes'] = 'mso'; $in['paste_text_linebreaktype'] = 'combined'; $in['plugins'] = 'tabfocus,paste,media,fullscreen,wordpress,wpeditimage,wpgallery,wplink,wpdialogs'; $in['theme_advanced_buttons1'] = 'formatselect,forecolor,|,bold,italic,underline,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,justifyfull,|,link,unlink,|,wp_adv'; $in['theme_advanced_buttons2'] = …
Category: Web

Asynchronously render shortcodes in TinyMCE visual editor

I created an img shortcode (e.g. [img attachment="19"]) that I want to render in real time in TinyMCE visual editor. So, I created a plugin for TinyMCE that replaces the shortcode in real time. Here is a portion of the Javascript code I wrote (inspired by this tutorial): (function() { tinymce.create('tinymce.plugins.mypluginname', { init : function(ed, url) { var t = this; t.url = url; //replace shortcode before editor content set ed.onBeforeSetContent.add(function(ed, obj) { obj.content = t._do_spot(obj.content); }); //replace shortcode as …
Category: Web

Customer Support: TinyMCE stopped working (on some computers)

I'm sold on this one. A client has reported he can't edit any text on posts or pages on his WordPress site, claiming the visual editor text is white and he can't click on any buttons. Not even the HTML tab works. He sent me a screenshot where I can see his text is appearing on white (even with red markings from the spellchecker) and TinyMCE buttons are not loaded. He reports the same error using both the latest Firefox …
Category: Web

Translate MCE button text/tooltip in custom plugin

I am using a custom MCE button in my wordpress custom plugin below is my code function enqueue_plugin_scripts($plugin_array) { //enqueue TinyMCE plugin script with its ID. $plugin_array["related_post_button"] = plugin_dir_url(__FILE__) . "index.js"; return $plugin_array; } add_filter("mce_external_plugins", "enqueue_plugin_scripts"); and the js index.js is (function() { tinymce.create("tinymce.plugins.related_post_button", { //url argument holds the absolute url of our plugin directory init : function(ed, url) { //add new button ed.addButton("related_btn", { title : "Add Related post shortcode", cmd : "related_command", icon: "custom-mce-icon", }); //button functionality. ed.addCommand("related_command", …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.