Tagged: 

This topic contains 5 replies, has 3 voices, and was last updated by  Jason 3 years, 1 month ago.

  • Author
    Posts
  • #6778

    eflouret
    Participant

    Hi,

    I would like to show only four buttons (b, i, link, unlink) in my frontend editor.

    I can’t find a way to do that with Piklist, so I tried with the regular wordpress hooks/filters/actions whatever.

    The problem is that all of them need an editor ID, which it isn’t an option (as far as I know) in the Piklist editor field.

    Is there a way I can display a custom toolbar in my editor field?

    Thanks!

    Enrique

  • #6784

    Steve
    Keymaster

    @eflouret– Welcome to the Piklist community!

    Which hooks/filters/actions are you using to achieve this?

  • #6786

    eflouret
    Participant

    Hi Steve,

    Sorry, but I didn’t test anything yet. I saw several tutorials, but all of them took quite different approaches. Some of them asked for a wp_editor instance ID like this one:

    add_filter( 'teeny_mce_buttons', 'my_editor_buttons', 10, 2 );
    function my_editor_buttons( $buttons, $editor_id ) {
        return array( 'formatselect', 'bold', 'italic' );
    }

    I believe that there is an ID attribute in the WP_EDITOR() that I can pass to piklist, but I didn’t try it. Besides, how will that work with add_more fields?

    Sorry, although I can code a bit of PHP, I’m not a programmer.

    Thanks

    Enrique

  • #6787

    eflouret
    Participant

    Ok, this works (source: http://rachievee.com/wp-tutorial-remove-tinymce-buttons/)

    function remove_bold_tinymce_button( $buttons ){
          //Remove bold button
          $remove = 'bold';
    
          //Find the array key and then unset
          if ( ( $key = array_search( $remove, $buttons ) ) !== false )
    		unset( $buttons[$key] );
    
          return $buttons;
     }
    
    add_filter( 'teeny_mce_buttons', 'remove_bold_tinymce_button' );

    You can use it with ‘teeny_mce_buttons’ or ‘mce_buttons’. This function will remove the Bold button. Not that I want that, but it is just an example of how to remove a button.

    But it alters all instances of the editor in your site.

    I have to find a way to make this work only in the frontend and in the add_more fields too. I guess that should be fairly easy.

    Any suggestions?

    Enrique

  • #6805

    Steve
    Keymaster

    Enrique–

    You can let WordPress tell you. Try this. It should display the $editor_id for you.

    function my_editor_buttons( $buttons, $editor_id ) {
    	print_r($editor_id);  // display id
    	return array( 'formatselect', 'bold', 'italic' );
    }
    add_filter( 'teeny_mce_buttons', 'my_editor_buttons', 10, 2 );
    
  • #6830

    Jason
    Keymaster

    Hi @eflouret!

    Checking for the front-end is pretty easy, just throw !is_admin() in your teeny_mce_buttons hook. Nothing is stored for the editors, so you can do it per request like that.

You must be logged in to reply to this topic.