Support » Developing with WordPress » Change ‘Save changes’ title button in my custom button

  • Hello, I have a question.
    In my custom plugin, for example, when I create a tab, I have a basic wordpress button “Save changes”
    I added an action to it in that I would like to change its name as well
    How could I do it?
    Or if I can’t, how could I make a custom button to which I can assign an action?
    Basic button from wordpress:
    I would like to make such a custom button and assign it an action, how could I do it?
    I added this for basic button

    add_action('updated_option', array ($this, 'generate_feed'), 10, 3);
Viewing 3 replies - 1 through 3 (of 3 total)
  • @danield99 Is your custom plugin adding a tab to a block in the editor or adding a tab to an admin page? I couldn’t quite tell from your screenshot its intended use.

    Would you be able to add a bit more information about what you’re trying to achieve such as what page you are trying to create the functionality on? If you have any current code you would be willing to link to, that might help as well.

    In short: there’s definitely a way to create a custom button to assign an action, but which action and how you would do that all depends on where it’s intended to be used. Thank you.

    Thread Starter danield99


    Hi. I would simply like to add a button and add an action to it and delete that “save changes” from my plugin.
    I don’t know how I could do that.

    OK, assuming you have a custom screen you are adding the button to (instead of creating a block), you should be able to take the following steps to add some custom logic for your button:

    1) When the button submits, I assume you want it to submit a form. Make sure your button has a unique name and implements a nonce for security.
    2) Add a custom function into a hook that has the appropriate timing of when you want to fire your custom logic. For example, if you want to run your custom logic when WordPress is initialized, you’d set up something along the following:

    function maybe_process_button(){
        // Check for the form field, either in $_POST or $_GET, depending on how it was set up
        // Check for valid nonce
        // If that field exists and has the expected value, then run your custom logic
    add_action( 'init', 'maybe_process_button' );

    3) That should do what you need to do for processing custom logic. If you’re trying to hook into existing admin hooks, you’d take the logic described and replace it with the specific action you are trying to target.

    I hope that helps clarify how you’d be able to set the button up to work as you desire.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.