Tag Info

Hot answers tagged

17

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 ...


11

I recently got this working. You should search and replace metaname with your meta box name. The key to maintaining formatting was using wpautop(); when saving the data. add_action( 'add_meta_boxes', 'add_metaname_box'); add_action( 'save_post', 'metaname_save'); function add_metaname_box() { add_meta_box( 'metaname_id', __( 'metaname ...


10

You pretty much had it, according to the description. Here's what you might be looking for for instances 2 and 3 (for instance 1 you can leave the settings empty to get the default set of buttons): Instance 2: wp_editor( $distribution, 'distribution', array( 'media_buttons' => false, 'textarea_rows' => 8, 'tabindex' ...


9

It is almost code golf, but this is the smallest piece of code that I could up with that will create a button on the Visual editor to turn the current paragraph in a <h2> block. add_filter( 'tiny_mce_before_init', 'wpse18719_tiny_mce_before_init' ); function wpse18719_tiny_mce_before_init( $initArray ) { $initArray['setup'] = <<<JS ...


9

The follow small plugin create a custom buttom inside line 1 of the WordPress TinyMCE Version 4, tested in WP Version 3.9-beta2. The plugin have var_dump include to understand the values. It 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.php ...


8

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 ) ) ...


8

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 ...


7

Ok apparently WordPress keeps track of what kind of editor (visual or html) is active as a class which is added to the content wrapper so here is a solution that will get you the latest content in the editor function get_tinymce_content(){ if (jQuery("#wp-content-wrap").hasClass("tmce-active")){ return tinyMCE.activeEditor.getContent(); ...


7

Just wrote the function. It'll display the tinymce editor in every custom taxonomy description right now. Surely you can edit to show it for only some specific taxonomy. /** * Display advanced TinyMCE editor in taxonomy page */ function wpse_7156_enqueue_category() { global $pagenow, $current_screen; if( $pagenow == 'edit-tags.php' ) { ...


6

This should be what you're looking for - put this code into your theme's functions.php file: add_filter( 'tiny_mce_before_init', 'yourprefix_tiny_mce_before_init' ); function yourprefix_tiny_mce_before_init( $init_array ) { // filter styles: $init_array['theme_advanced_styles'] = "your_style=your_class"; // filter formats: ...


6

Here is a nice and fairly new (a year old) tutorial i've read a few days ago http://www.garyc40.com/2010/03/how-to-make-shortcodes-user-friendly/ He as a great example and you cal also download the source files and get a better understanding.


6

you can set the params via array on the wp_editor() function; an exmaple $settings = array( 'tinymce' => array( 'setup' => 'function (ed) { tinymce.documentBaseURL = "' . get_admin_url() . '"; }', ), 'quicktags' => TRUE, 'editor_class' => 'frontend-article-editor', 'textarea_rows' => ...


6

Use the filter 'mce_external_languages'. From wp-includes/class-wp-editor.php: The following filter loads external language files for TinyMCE plugins. It takes an associative array 'plugin_name' => 'path', where path is the include path to the file. The language file should follow the same format as /tinymce/langs/wp-langs.php and ...


6

esc_html() and esc_textarea() are, appropriate to their names, escaping functions and really meant for display rather than sanitizing or validating. I would use wp_kses() or wp_kses_post() (which is just wp_kses() with the global $allowedposttags) to sanitize input from a wp_editor() field before saving.


6

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; ...


5

Solution 1 This works as javascript solution: Example: tinyMCE.activeEditor.dom.addStyle('p {color:red; font-size:28px;}'); just open your js console and paste it for a quick test. To target a specific editor one should use: tinyMCE.getInstanceById('##editorID##').dom.addStyle('p {color:red; font-size:28px;}'); This will inject the provided string ...


5

Best solution for what you want to accomplish which is essentially to make the next page feature more user friendly for your authors is to add a TinyMCE button that will do this for you. This may be a bit complicated so hold your hat. To avoid this answer being the length of a thesis, I have added comments in all codes to help you understand what each ...


5

There's too much to put the whole answer here so checkout this guide: http://wp.smashingmagazine.com/2012/05/01/wordpress-shortcodes-complete-guide/ You have to create a Javascript file that takes action from the button you register through WordPress that inserts the TinyMCE button into the editor.


5

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 ...


5

Your problem i believe are the lines that follow the enqueues and print scripts, you're mixing Javascript with PHP.. Javascript goes inside the HTML section of a PHP file or inside an echo statement. This page of the codex gives an example for adding a button to TinyMCE inside WordPress. However that codex entry might be a bit dated, so in the event of ...


5

Use this class: http://www.deluxeblogtips.com/p/meta-box-script-for-wordpress.html and then call the metabox like this (don't forget to read the manual and view some examples): $meta_boxes[] = array( 'id' => 'textmetabox', 'title' => 'Your Meta Box Title', 'pages' => array('post', 'slider', 'whatever-your-cpt-is'), 'fields' => ...


5

Pre WP 3.3: http://www.dev4press.com/2010/tutorials/wordpress/tips/add-rich-text-editor-to-your-plugin/ If you are using WP 3.3 or later you might look up wp_editor: http://codex.wordpress.org/Function_Reference/wp_editor $settings = array( 'teeny' => true, 'textarea_rows' => 15, 'tabindex' => 1 ); wp_editor(esc_html( ...


4

Instead of requireing admin.php you just can use WP built-in ajax functionality, even if it's not ajax in this case. Add a hook add_action('wp_ajax_my_plugin_function', 'my_plugin_function_callback'); Create your output function (callback) function my_plugin_function_callback() { // do stuff } Call it this way instead of: file : url + ...


4

I'd suggest using Ozh's TinyMCE Advanced plugin. It lets you add a 'Paste from Word' option that takes care of all of that for you. However, if you're not interested in that, you have a few more options. Like this: function get_rid_of_mso_junk( $content ){ return preg_replace( '@(mso|panose)[^:]{1,25}:[^;]+;(\s+)?(\n+)?@i', '', $content ); } add_filter( ...


4

I found a very helpful blog post which shows exactly how to accomplish what I am after with only three small changes to the user-edit.php page. First Change I had to add a class name to the <textarea> tag for the description. <textarea name="description" id="description" rows="5" cols="30" class="CLASS_NAME_HERE"><?php echo ...


4

Here's (a pared-down version of) what I use to custom-configure TinyMCE: // http://tinymce.moxiecode.com/wiki.php/Configuration function cbnet_tinymce_config( $init ) { // Don't remove line breaks $init['remove_linebreaks'] = false; // Pass $init back to WordPress return $init; } add_filter('tiny_mce_before_init', 'cbnet_tinymce_config'); ...


4

You can hook into tiny_mce_before_init to modify the TinyMCE arguments to set the readonly attribute. For example (using PHP 5.3): add_filter( 'tiny_mce_before_init', function( $args ) { // do you existing check for published here if ( 1 == 1 ) $args['readonly'] = 1; return $args; } ); This will make the TinyMCE readonly, however ...


4

This works: tinymce.create('tinymce.plugins.tinyplugin', { init : function(ed, url){ ed.addButton('tinyplugin', { title : 'map', onclick : function() { tb_show("", "../wp-content/plugins/myplugin/test.php?"); tinymce.DOM.setStyle(["TB_overlay", "TB_window", ...


4

You can add an editor-style.css stylesheet in your theme which mimics the look-and-feel of your blog. Here are some tips on how to do that (you'll need to touch functions.php too): http://www.deluxeblogtips.com/2010/05/editor-style-wordpress-30.html The first two styles in that example are the important ones; usually what I do is just copy over and rename ...


4

The TinyMCE has an Filter for all allowed tags. You can change the tags, there are set in standard for your options and the editor fitler the tags. Its not necassary, that you filter after save. Example for enhanced tags: function fb_change_mce_options( $initArray ) { // Comma separated string od extendes tags // Command separated string of ...



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