- This topic has 7 replies, 2 voices, and was last updated 1 year, 3 months ago by
Steve.
-
AuthorPosts
-
-
October 12, 2020 at 2:11 am #10989
thorMemberHow can I add a button to the editor? I need the “anchor” button back in WordPress. If it is added like this: https://codex.wordpress.org/TinyMCE_Custom_Buttons it appeats fint in the normal wp-editor. Not in the Piklist field, however.
piklist('field', array( 'type' => 'editor', 'field' => 'intro_content', 'label' => 'Intro text', 'template' => 'field', 'options' => array( // Pass any option that is accepted by wp_editor() 'wpautop' => true, 'media_buttons' => false, 'shortcode_buttons' => false, 'teeny' => true, 'dfw' => false, 'quicktags' => true, 'drag_drop_upload' => false, 'tinymce' => array( 'resize' => false, 'wp_autoresize_on' => true, 'toolbar1' => 'bold,italic,underline,link,unlink', 'toolbar2' => 'anchor', ), 'textarea_rows' => 10, ), 'columns' => 12, )); -
October 13, 2020 at 3:43 pm #10990
SteveKeymaster@thor– This one was fun to figure out.
It looks like
anchorwas removed from WordPress 6 years ago: https://core.trac.wordpress.org/ticket/28394#comment:2You would need to find the TinyMCE plugin and install it. Luckily, there is a plugin that already includes it. If you install and activate your
anchorbutton will appear: https://wordpress.org/plugins/tinymce-advanced/In my tests, that plugin also added a second toolbar. Passing this worked:
,'toolbar1' => 'bold,italic,underline,link,unlink,anchor' ,'toolbar2' => '' -
October 13, 2020 at 3:45 pm #10991
SteveKeymasterYou can also try pulling out the anchor js from that plugin and including it in your plugin/theme so your not reliant on that plugin for this.
-
October 14, 2020 at 1:55 am #10992
thorMemberThanks Steve,but I can’t get it working. I had a similar plugin (only for bringing back the anchor). It works in the regular editor but it is not appearing piklist. The same with tinymce-advanced.
Any other suggestions? Are there any settings in the piklist editor field that prevents the tinymce plugin from inserting the buttons?
-
October 14, 2020 at 2:01 am #10993
thorMemberHmm, there must be another plugin interfering. I just tried the approach on a clean install and it works. It has something to to with custom post type since it works on pages.
-
October 14, 2020 at 2:15 am #10994
thorMember'teeny' => true
– was the problem 😀And perhaps buttons can be added in teeny mode – https://wordpress.stackexchange.com/questions/248019/how-to-add-button-in-tinymce-teeny-mode. But for now I’ll just set teeny to false
-
October 14, 2020 at 2:28 am #10995
thorMemberThe weird thing is that if I add a teeny editor as the first Piklist field it prevents the next non-teeny editor from showing the buttons from various plugins. Is it a Piklist bug?
piklist('field', array( 'type' => 'editor', 'field' => 'intro_content', 'label' => 'Intro text', 'template' => 'field', 'options' => array( 'wpautop' => true, 'media_buttons' => false, 'shortcode_buttons' => false, 'teeny' => true, // If true - next editor will not have various tinymce plugin buttons 'dfw' => false, 'quicktags' => true, 'drag_drop_upload' => false, 'tinymce' => array( 'resize' => false, 'wp_autoresize_on' => true, 'toolbar1' => 'bold,italic,underline,link,unlink', 'toolbar2' => '', ), 'textarea_rows' => 10, ), 'columns' => 12, )); piklist('field', array( 'type' => 'editor', 'field' => 'my_content', // 'post_content' is the field name of the WordPress default editor 'scope' => 'post', // Save to the wp_post table 'label' => 'Post Content', 'template' => 'field', // Only display the field not the label 'options' => array( // Pass any option that is accepted by wp_editor() 'wpautop' => true, 'media_buttons' => true, 'shortcode_buttons' => true, 'teeny' => false, 'dfw' => false, 'quicktags' => true, 'drag_drop_upload' => true, 'tinymce' => array( 'resize' => false, 'wp_autoresize_on' => true, ) ), 'columns' => 12, )); -
October 14, 2020 at 2:09 pm #10996
SteveKeymasterHonestly, I’m not sure if that is a Piklist issue or TinyMCE. You may have to work around it
Also, instead of using the full tinymce-advanced plugin, you can:
1) copy this file into your theme/plugin: https://plugins.trac.wordpress.org/browser/tinymce-advanced/tags/5.5.1/mce/anchor/plugin.js2) Include this code in your theme/plugin:
function my_custom_plugins( $plugins ) { $plugins['anchor'] = '[path to]/tinymce-advanced/mce/anchor/plugin.js'; return $plugins; } add_filter( 'mce_external_plugins', 'my_custom_plugins' );And the anchor button will work
-
-
AuthorPosts
- You must be logged in to reply to this topic.