I have to insert some condition if the current page is a category page or not.
$category = single_term_title("", false); $catid = get_cat_ID( $category );
You can also view your WordPress category ID by editing it. Simply open a category to edit, and you'll see the category ID in the browser's address bar.
So, what you need to do is add '/wp-admin/' at the end of the domain (homepage URL) of the website. If it redirects to the login page, then you can determine that the website uses WordPress. For example, if your website URL is 'https://example.com', then add '/wp-admin/' at the end of it.
you can use this for getting category
is_category();
is_category( '1' ); // where 1 is category id
is_category( 'test' ); // where test is category name
is_category( 'test-ing' ); // where test-ing is category slug
I have found the way to do it by checking if $cat_id
is available or not on that page by the following.
$cat_id = get_query_var('cat');
Now we can check if $cat_id is available then it is a category page otherwise it is not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With