Instead of nuking the entire widget, you should put your conditional statements within the widget itself:
public function widget( $args, $instance ) {
if ( is_singular( array( 'post_type_a', 'post_type_b' ) ) ) {
// display your widget here
}
}
Since you’re not printing $before_widget
and $after_widget
, there won’t be any output for this widget unless the conditions are met.
Related Posts:
- How do test if a post is a custom post type?
- Where to put my code: plugin or functions.php?
- Conditional for single-{post-type}.php
- Custom Post Type Data in Sidebar widgets?
- Including Custom Post Types in “Recent Posts” Widget
- Limit widget to a specific registered sidebar
- is_singular() not working if called via callback function of admin-ajax.php
- functions.php conditional tag only for custom post type
- Include custom post types in categories widget
- Exclude custom function content from certain pages
- Get template part based on custom taxonomy term
- Including a custom post type in the Archives widget
- If on term-page -> get the current term?
- custom post type upcoming post and past post
- changing default comment form arguments [duplicate]
- How to embed form data within the ‘Add new post’
- is_page_template not working as expected
- Add custom post types stats to a custom dashboard widget
- How to create another version of the Category widget?
- ‘Pages’ widget alternative for custom post types?
- Including Custom Post Type posts in a page template contextually (or should I widget?)
- remove child post from custom post type archive
- if custom posts type exists and there are posts load script
- Need help targeting a custom post type with conditional tags
- Why would this IF statement not work? [closed]
- right_now_content_table_end function not working?
- custom comments on specific post type
- Excluding custom post types
- Custom Post Type Loop throws 500 error when used in widget
- How to create Blog Post Specific Widget
- Custom page sidebar using Template dropdown box
- Random image from tag/custom type on sidebar
- Widget: Custom Post Type Post Listing Dropdown on Admin Side
- Is there a conditional tag to determine whether the post is _any_ custom post type?
- Conditional Query of Custom Post Type and custom taxonomy
- Display Custom Toxonomy In WordPress and theme Widgets category selection dropdown list
- Custom Widget WP_Query problem
- Hide a widget inside a div on specific type of post
- Filter widget outputs
- How to run filter only on custom post type edit screen
- Conditional statement for if archive page has posts which contain certain taxonomies/categories/tags, show those terms
- Custom Post Conditional for Parent & Child Single.php?
- Set Custom Post Type in Widget Settings for use in Widget
- Want to be able to sign up subscribers as authors
- Conditional for a Single Post That Belongs to a Category?
- How to show only the most recent post on my custom post type archive?
- the_post_thumbnail call removing li in code
- how to set a WP Plugin’s url
- Conditional Tags for specific category of custom posts
- Why isn’t a list of posts from my custom post type displaying in this widget?
- Move Genesis Single Page/Single Post Title
- How to check if post/page or taxonomy post is published by admin
- TinyMCE Buttons on Certain Post Type
- How to get dropdown instance value in WordPress custom Widget
- Display message if no posts in Custom Post Type loop
- Showing taxonomy terms on custom post type
- Check if custom post is a parent?
- Post Query not working
- Methods for development wordpress themes [closed]
- Redirect to URL if x number of days passed
- comments hooks on custom post type
- Conditional Statements
- If custom taxonomy else conditional [closed]
- If tag exists, then echo once
- Show specific content on parent custom post type and all children
- Use conditionals with wp_enqueue_style to attach stylesheet according to post type displayed
- Truncate custom post type content
- How to exclude categories from a sidebar with active widgets in it?
- Replace Content of Sidebar on Custom Post Type
- Custom Page Template – Widgets of wrong sidebar
- How can I check the rewrite slug of current post type listing page
- How to add custom PHP code in post header?
- Widget area for individual posts (custom post type)?
- $_SESSION Not working after X amount of page views
- How do I get the posts from single page custom post type from a sidebar to display in a page?
- I want to link an author to everything from any post type that they publish on the website
- conditional based upon the count of current user’s published custom posts
- retrieve custom post image through widget
- Custom post type not being pulled in widget
- Custom metabox fields not saving when limited to a certain CPT
- Can not hook into custom post type template with: is_page() conditional?
- Custom post types archive
- multiple custom post type category selection search
- how to override menu widget?
- Displaying database table in backend of wordpress
- Diffrent search templates for different post types
- Conditional Tags If Custom Post Parent & Child?
- Filter CPT based on meta box value using Flexible Posts widget?
- Creating Multiple Admin Widget Page with Calling One Sidebar
- Custom Post Query Combined with Conditional Tags
- fetch meta fields inside a widget
- Radom post image/link based on custom taxonomy
- empty dashboard for custom role
- Code in custom widget queries all posts, when it should only query the current post
- How to add post type in masonry posts elementory widget
- Post_type doesn’t work for widgets?
- Conditional statement checking two conditions for CPT and Custom Taxonomy [closed]
- strange conditional tag behaviour [duplicate]
- How to display custom message for (Genesis) featured posts if no posts
- Custom post type is_singular condtional not working when managing sidebar display