Hot answers tagged tinymce
10
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 ...
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
...
8
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' ...
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
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
This should be what you're looking for - put this code into your theme's functions.php file:
function yourprefix_tiny_mce_before_init( $init_array ) {
$init_array['theme_advanced_styles'] = "your_style=your_class"; // filter styles
$init_array['theme_advanced_blockformats'] = "p,h3,h4,h5"; // filter formats
return $init_array;
}
add_filter( ...
6
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();
...
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
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 ...
5
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.
5
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 ...
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 ...
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
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
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
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' => ...
4
Use add_editor_style
e.g.: functions.php
add_editor_style('custom-editor-style.css');
http://codex.wordpress.org/Function_Reference/add_editor_style
4
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.
4
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 ...
4
The problem is "When the data managed by the plugin is edited. You have to set your own dirty-flag (e.g. a value in a hidden input field, setup a js-variable) and check your dirty-flag if the user leave the page. But how could you check if the data in the metabox is edited? Are there some suitable hooks in the plugin? If not, you can use jQuery/JS OnChange ...
3
Yes!
Use the mce_buttons_2 filter to add
buttons to the second row.
Use the mce_buttons_3 filter to add buttons
to the third row.
Here's an example of what I use:
function mytheme_mce_buttons_row_3($buttons) {
$buttons[] = 'fontselect';
$buttons[] = 'fontsizeselect';
$buttons[] = 'code';
$buttons[] = 'sup';
$buttons[] = 'sub';
...
3
t31os answer is great. Just a side note: to obtain the path to the image add
init : function(ed, url) {
theurl = url;
},
right before createControl: function... and now you can use it in
var c = cm.createSplitButton('onehalf', {
title : 'My split button',
image : theurl + '/theicon.png',
onclick : function() {
...
3
It should be pretty straight-forward, copy the relevant pieces of code from the page you linked to into your existing TinyMCE plugin, update a few strings... done!..
Start with this for your TinyMCE plugin JS and see how you get on..
// JavaScript Document
(function() {
// Creates a new plugin class and a custom listbox
...
3
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 + ...
3
First add your additional buttons inside the buttons callback..
function register_button($buttons) {
array_push($buttons, "quote","wpse-rules");
return $buttons;
}
Then add additional buttons function inside the plugin javascript..
init : function(ed, url) {
ed.addButton('quote', {
title : 'Add a Quote',
...
3
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');
...
3
Your if statement wants the user to be able to posts AND pages, which only applies to admins and editors by default. Are you sure editors cannot see the buttons? If you want anybody who can edit posts to see the buttons (e.g. authors and contributors) take out the check for edit_pages or make it an or statement (which is an unlikely situation in most ...
Only top voted, non community-wiki answers of a minimum length are eligible
