Viewing 7 reply threads
  • Author
    Posts
    • #10989
      thor
      Member

      How 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,
      ));
    • #10990
      Steve
      Keymaster

      @thor– This one was fun to figure out.

      It looks like anchor was removed from WordPress 6 years ago: https://core.trac.wordpress.org/ticket/28394#comment:2

      You 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 anchor button 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' => ''
    • #10991
      Steve
      Keymaster

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

    • #10992
      thor
      Member

      Thanks 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?

    • #10993
      thor
      Member

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

    • #10994
      thor
      Member

      '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

    • #10995
      thor
      Member

      The 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,
      ));
      
    • #10996
      Steve
      Keymaster

      Honestly, 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.js

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

Viewing 7 reply threads
  • You must be logged in to reply to this topic.