Giuseppe
Giuseppe

Reputation: 1

Hook for specific wordpress page

I don't know how to add a specific action for a specific page. I'm creating a new plugin that have to run only on a new page, specially created. I know how to run it in general, but i don't know how to make it run only on a specific page id.

Upvotes: 0

Views: 850

Answers (1)

Arnout Pullen
Arnout Pullen

Reputation: 187

You can use is_page() like this:

add_action( 'my_hook', 'custom_my_hook' );
function custom_my_hook() {
    if ( is_page( 123 ) ) { // replace 123 with your page id
        // only execute on page 123
    }
}

Upvotes: 1

Related Questions