The problem is that is_category
does not do what you thought it does. is_category( 'keep' )
tests that the current page is a category archive for the category keep
, it does not check if the current attachment/post is in the keep
category.
The official WordPress developers docs for is_category
start with:
Determines whether the query is for an existing category archive page.
https://developer.wordpress.org/reference/functions/is_category/
Instead, what you want is to check if the current post has a category assigned, aka has_category
:
has_category( string|int|array $category = '', int|WP_Post $post = null ): bool
Checks if the current post has any of given category.
https://developer.wordpress.org/reference/functions/has_category/
Related Posts:
- remove links from images using functions.php
- Masking logout URL
- How to add classes to images based on their categories?
- Logout/login redirect CSS issue
- Paged Single Post doesn’t redirect to the main url after Removing Pagination
- Auto delete WordPress images/thumbnails (all sizes) and featured after X days/hours, or similar?
- redirect wp-login.php to another page
- How do I redirect upon login a specific user based on role?
- How to add a rel attribute to images that contains their categories?
- Best way to programatically add “rel” attributes to page and post images
- What is the “icon” parameter in wp_get_attachment_image_src used for?
- Find first image on paginated post for Pinterest
- Ninja form Redirect depending on text field content [closed]
- How do I permanently Disable Attachment Post URL
- Redirect specific page in WordPress for first time visit
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- How do I redirect all 404 error url to Subcategory url
- Image rotation fails to regenerate custom sized thumbnail
- Display images that are not in the content
- 404 redirect to previous category
- Login Redirect if Logged in from Specific Page
- Redirect to another page if the user is logged in when pressing again the login button on menu bar
- Incorrect redirect after commenting
- Can’t filter wp_get_attachment_link
- Get ID of first image attached to a post
- How to stop wordpress from injecting hard-coded style into image attachments with captions
- How i can put $_GET codes in function.php?
- Why does get_template_directory_uri() not include “www”, only for enqueued stylesheets?
- How to hide image-url if no attachment?
- attachment page template? only show attachments for current post?
- How to get an attachment id from a filename
- Page get parameter doesn’t work with is_single() function
- What are the meta fields for an attachment?
- Redirect website domain (including all pages) to external URL after Popup message (few seconds)
- Contact Form 7 If Condition
- Solved: redirect to another page using functions.php
- Redirect to other page if login
- Logout Redirect and also WP-login.php Redirect
- How to add array [closed]
- WordPress website keeps loading the maintenance page
- Remove attachment page for audio media type only
- Redirects based on a JSON file
- Get Attachment Category Name
- template_redirect action only firing if logged in
- How d0 i get the number of attachments in the post
- How to redirect Subscribers on login to specific page, when logging in from a Page
- Different image using srcset function
- Auto delete content in specific folder inside media library
- Redirect to one of two pages after data submitted, depending on the current url
- WP_Query for Attachments not working as expected
- How to update an image attachment’s alt text from a custom field when saving a post?
- Wildcard 301 Redirect Using Theme Function
- Competing Login Redirects – Need to be Combined?
- Postback redirect through add_action is not triggered
- Restrict access if logged out except for homepage
- Redirect specific author posts to another url
- Remove all video attachment, both files and post/postmeta from database?
- Custom download page
- How to create a function to redirect a specified page to another page
- Language switcher for subdomains
- Open image size links in a page instead of direct image link
- Allow the access over wp-login.php
- Set thumbnail from URL, by grabbing image in functions.php
- How to request login for user but not for bots
- Making an under maintenance page (without using plugins)
- Template Redirect Function Only Working When Logged In
- Redirecting after login except for a specific page
- How to redirect using a custom wordpress api endpoint after form submission?
- Missing feature image link function
- What’s the difference between home_url() and site_url()
- Remove “Category:”, “Tag:”, “Author:” from the_archive_title
- get_template_directory_uri pointing to parent theme not child theme
- How to customize the_archive_title()?
- remove empty paragraphs from the_content?
- What is the “with_front” rewrite key?
- Why use if function_exists?
- How to override parent functions in child themes?
- wp_enqueue_script was called incorrectly
- Add multiple custom fields to the general settings page
- Ajax call always returns 0
- 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
- How long does a deprecated function live in core?
- Solution to render Shortcodes in Admin Editor
- How to add a data attribute to a WordPress menu item
- What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
- remove_action on after_setup_theme not working from child theme
- plugins_url vs plugin_dir_url
- Remove type attribute from script and style tags added by WordPress
- How to run a function every 5 minutes?
- Best way of passing PHP variable between partials?
- Upload Multiple Files With media_handle_upload
- How to display custom field in woocommerce orders in admin panel?
- Adding fields to the “Add New User” screen in the dashboard
- Issues with title-tag and document_title_parts
- How do I get the current edit page ID in the admin?
- How to check if a user exists by a given id
- Why isn’t is_page working when I put it in the functions.php file?
- Add tags to the section via functions.php
- Add image size if page template
- How to create a custom order status in woocommerce!