Sounds like you’re looking for has_category()
, which
Checks if the current post has any of given category.
You would use it, for example in single.php
, like so,
<?php if ( has_category( array( 'cat-a', 'cat-b', 'cat-c' ) ) ) : ?>
<div>
<?php echo do_shortcode( 'some_shortcode' ); ?>
</div>
<?php endif; ?>
Related Posts:
- Counting number of posts in a category and its sub categories and displaying result using shortcode
- How to manually fix the WordPress gallery code using PHP in functions.php?
- Shortcode putting html such as
- Shortcode created to check language not works
- Allow authors to post only in categories they create in WordPress
- How to Populate the list of custom post type categories
- Php string not working in WordPress Functions.php [duplicate]
- Add/echo div with Analytics-Code to function in functions.php
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- How can I default to all WordPress roles when parameter is not included in shortcode?
- WordPress menu deletes when trying to add a hook
- Problems with function on function.php
- Use template for posts with a particular category grandparent
- Recent post display using shortcode
- Nested shortCode functions in the functions.php file
- Making Quote Plugin more efficient
- Woocommerce – remove product from category
- Shortcode content output but not in correct place
- is_page “range” for if statement?
- PHP code inside shortcodes
- Shortcode content filter?
- get current product name in functions.php
- Trigger popup in a php if/else statement
- get post based on category chosen in drop down – The ajax method
- How to output a PHP file values by shortcode?
- Showing content from one page on another
- Get value from shortcode to do something
- How to exclude category ID from Looper in WordPress
- Add a specific part of current category page url to shortcode
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How to pick the default selected value in wordpress dropdown?
- Get page that displays all children of taxonomy parent
- Pass php dynamic variable to shortcode
- How to Reference/Echo Variable from Another PHP Function
- Remove echo from shortcode
- Redirect to another page using contact form 7? [closed]
- Shortcode with PHP issue “Undefined index”
- Dilemma of Populating all the categories in a drop down list
- Shortcode from a function not working
- Display Data in Table from External Database in WP using Shortcodes
- Is it possible to return content, and then also continue to do other things?
- ::before on open/close function [closed]
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Creating WordPress Shortcode with Variable
- Shortcode to find and replace URL
- Displaying posts based on category
- calling a custom field value inside functions.php
- List all blogs, but exclude the main site
- Shortcode to embed Edit Account form not working
- Shortcode for Listing Users from Meta Value?
- How to get current post category details inside “loop”?
- Cant display an image via PHP in wordpress
- Show all tags within a category?
- Post not populating for custom post type based on category selection
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- How to return a string that has a jQuery and Ajax inside in a shortcode?
- Create special button on WP Tiny MCE Posts Editor for Shortcodes
- Updating Metadata with Shortcode
- Counting number of posts in multiple (sub)categories using shortcode
- Display logged in user name and lastname on page
- Create shortcode for metabox gallery
- How do I reopen the (Popup Maker) after entering the correct password for a password protected page?
- How can I prevent a shortcode div from extending beyond its boundaries?
- Get parent category name when only child category is applied to a product
- Gravity Forms: How to add PHP function to confirmation conditional shortcode?
- wpdb->query returns different value to phpMyAdmin
- How to move a post from one category to another
- Display a custom name when the user has no name settle in his account
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Notice: Undefined variable
- Hide a specific category title from displaying on site
- Display current user metadata on WordPress page
- Reload page with a different shortcode when a user selects from a dropdown
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- Offset with ajax load more posts duplicates
- Shortcode’s output to use as other shortcode’s parameter
- Populate Posts based on category selected using AJAX that means without page refresh
- All categories options or All categories not Populating
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- Open/closed function [closed]
- Need to Echo A Url path to show on a wordpress page
- Short code into PHP
- Wrapping shortcode content in a span or link
- Need help with PHP functions
- Get category id for a custom category and display it in a class
- How to have Function of a plugin using global vars into a shortcode?
- Overwriting a Shortcode
- Shortcoding with Divs
- Displaying categories
- Whats wrong with my code? Need To add String to shortcode? [closed]
- My title is showing after the shortcode
- A next page function with shortcode?
- Shortcode to include PHP file, pass various parameters to include?
- How to insert the first letter in uppercase [closed]
- WP Custom tables query
- Display terms on product page with shotrcode
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- How call WordPress shortcode inside function file
- Exclude a category ID from the following function