Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wordpress - how to add WYSIWYG to textarea with a specific class

i need to add any wysiwyg to a textarea with a specific class in wordpress and i dont't know how to do it.

the best solution for me is gonna be to download some wp plugin where i should put a class name of textarea i need to add wysiwyg and plugin should should add any wysiwyg to it. is there such plugin? if there is not then how can i solve this problem?

also while googling i found this code:

wp_editor( $content, $editor_id, $settings );

but i cant realize where i should put this inside my code.

any help appriciated!

like image 526
SuperYegorius Avatar asked Jan 15 '17 08:01

SuperYegorius


1 Answers

It depends on where your textarea is located - options page, settings page, meta box?

Say that it's located in an options page, and you have saved option called my_option. First you'd fetch that option:

$my_option = get_option( 'my_option' );

And then you'd call the editor

wp_editor( $my_option , 'my_option', array(
    'wpautop'       => true,
    'media_buttons' => false,
    'textarea_name' => 'my_option',
    'editor_class'  => 'my_custom_class',
    'textarea_rows' => 10
) );

This should display the TinyMCE editor in your textarea.

Check out the codex for wp_editor to see what other arguments you can set.

In case of post or page metabox, you'd save the options in a meta field and get them out with get_post_meta() function.

like image 179
dingo_d Avatar answered Nov 14 '22 21:11

dingo_d