Qwertzui11
Qwertzui11

Reputation: 75

Apply Wordpress function on specific page id(s)

I would like to apply the function below to three specific Woocommerce category page. For example (cat-a, cat-b, cat-c) Can I address them via Page ID, Slug, or somehow?

function remove_some_widgets(){
    unregister_sidebar( 'shop-sidebar' );
}
add_action( 'widgets_init', 'remove_some_widgets', 11 );

Upvotes: 1

Views: 951

Answers (1)

Nick
Nick

Reputation: 356

Use ispage()

function remove_some_widgets(){
    if(is_page()){
        unregister_sidebar( 'shop-sidebar' );
    }
}
add_action( 'widgets_init', 'remove_some_widgets', 11 );

As it is above, this will apply no any single page. You can add parameters to is_page() as you need:

// When any single Page is being displayed. is_page();

// When Page 42 (ID) is being displayed. is_page( 42 );

// When the Page with a post_title of "Contact" is being displayed. is_page( 'Contact' );

// When the Page with a post_name (slug) of "about-me" is being displayed. is_page( 'about-me' );

https://developer.wordpress.org/reference/functions/is_page/

Upvotes: 2

Related Questions