1

I want to have a custom button in my post editor, but everything I find online is for the previous, classic editor of WordPress and none of them seem to work with the new Gutenberg thing.

Red mark is where I want it to be. Either on top, alongside "Publish" and others, or inside a metabox: enter image description here

I tried:

add_action( 'edit_form_top', 'custom_button');
add_action( 'media_buttons_context', 'custom_button' );
add_action( 'post_submitbox_misc_actions', 'custom_button' );
add_action( 'post_submitbox_minor_actions', 'custom_button' );
add_action( 'post_submitbox_start', 'custom_button' );

where custom_button just echos a simple HTML element (button or link):

function custom_button(){
    $html  = '<a>Do Something</a>';
    echo $html;
}

What is wrong here? Is it something not supported in Gutenberg? Or do I need to set priorities on the add_action (I want to add this button from a plugin, not functions.php). Are there any alternatives to this?

4
  • None of those hooks are supported in the block editor. The block editor functions completely differently to the classic editor, and most (if not all) classic editor related hooks will not work in the block editor. Dec 22, 2022 at 13:53
  • Thanks @JacobPeattie. What's the alternative then?
    – Shahriar
    Dec 22, 2022 at 14:58
  • I'll need to double check if it's even possible in this specific spot, but it's late in my timezone so I'll come back to this later if somebody doesn't provide an answer sooner. Dec 22, 2022 at 15:28
  • Like in your successor question, don't use PHP. What you want instead is developer.wordpress.org/block-editor/reference-guides/slotfills/…. Classic editor was built with PHP - javascript - jQuery, however, block-editor is built with javascript - React - Redux (and using PHP only for REST responses)
    – Lovor
    Dec 29, 2022 at 0:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.