<?php
$current_user = wp_get_current_user();
if ( is_category( 'Cars' ) && 0 == $current_user->ID ) { ?>
<!-- HTML markup here -->
<?php } else { ?>
<!-- other HTML markup here -->
<?php } ?>
ID will be 0 in the $current_user
object, if the user isn’t logged in.
Related reading:
EDIT
Try using is_user_logged_in()
and in_category()
instead:
<?php
if ( in_category( 'cars' ) && ! is_user_logged_in() ) {
// Current post is in the category 'cars'
// and the current user is NOT logged in;
// do something
} else {
// do something else
}
?>
Related Posts:
- How to add featured image for category (without a plugin)?
- Category archive by year with permalink support /category/YYYY
- Create a category list page
- How do I get the category URL from get_the_category?
- How do I use the same post slug for different Categories?
- Default WP Gallery – show only galleries of a certain category
- How to tax query X number of posts related by tag first, then by category if not enough in tag-related
- Woocommerce product categories order [closed]
- How do I create a way for users to assign categories to a post from the frontend?
- Exclude sub category posts from category display
- How to hide a specific category posts in my monthly archive?
- Give specific category its own permalink structure
- Automated adding of one tag to all the posts in a category
- How to set up sub-categories for author pages?
- Assign different category colours to different categories in the main menu
- Deleting All tags except categories Wp database
- Action hooks returning old category instead of new category
- Category checkboxes in upload modal
- wp_list_categories, Add class to all list items with children
- Using separator with wp_list_categories
- How to mass-insert categories?
- Multi-site or categories?
- What is the advantage of using header-catname.php over is_category(‘catname’);?
- Custom WP_Query for current category (in category.php)?
- Why is get_the_category() saying that I have two categories?
- View the latest created categories
- Custom sidebar on category pages
- How do I get the category slug from wp_dropdown_categories
- Change the category of all posts in it
- How to display only posts assigned to a particular, isolated, subcategory
- How to hide some categories in category list under post in wordpress?
- exclude categories from search results
- List categories with posts
- Pagination not visible on woocommerce’s category page
- Only one post is showing on category page, why?
- wp_list_categories set order manually?
- Refine/Filter the Search Results by Category
- Putting a Category of posts under a Page
- change recent posts based on category
- category pagination got broken suddenly
- Why is it so hard to show the URL of the current category and how to do it?
- Where and when does WordPress invoke routes
- Getting category URL with hyphens, not spaces
- How can I change the tooltip in the_category?
- Category.php loads first before page.php?
- wp_update_post is not updating category
- How to get Next/previous_post_link to go through articles in top parent category
- What’s wrong with my wp database query?
- Fix Warnings that shouldn’t be necessary to fix
- how to get correct category of a post in case of multiple categories?
- Include WooCommerce product to all child categories
- Show button only for certain Woocommerce Product Categories
- get listed category’s id?
- Length of Category Names
- Category url generate 404 error
- Notice: Undefined variable: category_id
- Is it possible to create an alias/custom taxonomy for a category name?
- Style a category from category list
- Adding a page summary to a specific page
- Add a category on all archive category pages
- Multiple category columns and post counting list in wordpress Homepage
- Assigning certain pages or posts to use the template of the parent page or category
- Check for parent category
- I need advice on how to structure the categories according to the layout i have
- add current-cat class to single post page
- Problem with wp_create_category
- Assign author to category and not only posts
- Problem with pagination block in Gutenberg
- Product category display in tabs
- Sending all categories associated with a post to Google Ad Manager for use with .setTargeting
- Pull in an “Include” file based on a WordPress Category ID
- How to fetch common posts from two feeds?
- Sort categories by custom field in WordPress admin
- Why is URL Slug Saving Differently From How It’s Been Defined?
- How to set acf color field as background color to product category
- How to add all subcategories as submenu in WordPress menu
- Related to genre and category
- Get permalink to latest post in category
- How to noindex, follow a specific category wordpress?
- Category pages resolving with and without category prefix
- get taxonomy list in a page in the wordpress
- Is there a way to allow users to customize their feed view?
- Number of categories slowing down the site
- How to load terms of a custom taxonomy of a product in woocommerce cart page
- Subcategory Page 404ing
- displaying one category on one page
- Question About Messing With Category Pages and Descriptions
- How to exclude category and post_tag taxonomy while displaying custom taxonomy?
- Group Posts by First Letter of Title categories
- List Terms by category
- How to make 10 post of one category
- Listing category
- Anyway to hide a Category in the Categories section when adding/editing a post in WP Admin?
- Showing one post from each category, paged?
- Custom permalinks structure
- Weird html output of single_cat_title – is not inside of the html element?
- Limit authors on specific catogories
- how do I exclude a category foreach
- CPT Custom post type Tags & Categories not showing for ‘Editor’ user in editor
- Restricted category in Woocommerce [closed]