Community Forums › Forums › Archived Forums › Design Tips and Tricks › Why is my if (!in_category) statement not working?
- This topic has 6 replies, 2 voices, and was last updated 11 years, 2 months ago by brightlaunch.
-
AuthorPosts
-
February 18, 2013 at 7:30 am #20976brightlaunchMember
I want to remove the filter amd_zlrecipe_process_head everywhere except from posts in the listed categories... but it doesn't remove it anywhere... what am I missing?
If I just add remove_filter('wp_head', 'amd_zlrecipe_process_head'); then it is removed everywhere - so I know the problem is with the if-statement.
if ( !in_category (array ('11','284','285','288','289','291','292','293','294','295','296','270','273','274','275','279','280','282','283')) ) {
remove_filter('wp_head', 'amd_zlrecipe_process_head');
}February 18, 2013 at 7:44 am #20982cdilsParticipantYour if statement needs to be associated with an action or filter. Try something like this instead:
add_action('wp_head', 'custom_show_zlrecipe')
function custom_show_zlrecipe() {
if (!in_category() {
remove_filter('wp_head', 'amd_zlrecipe_process_head');
}
}
That code is untested, so try at your own risk. 🙂
Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂
I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.
February 18, 2013 at 8:33 am #20987brightlaunchMemberadd_action('wp_print_styles', 'custom_show_zlrecipe');
function custom_show_zlrecipe() {
if (!in_category (array ('11','284','285','288','289','291','292','293','294','295','296','270','273','274','275','279','280','282','283'))) {
remove_filter('wp_head', 'amd_zlrecipe_process_head');
}
}
accomplished most of what I needed. But, the scripts still show up on those category pages itself... I only want it to show for the posts in those categories...
February 18, 2013 at 8:34 am #20988cdilsParticipantMissing a semi-colon at the end of the first line:
add_action('wp_print_styles', 'custom_show_zlrecipe');
Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂
I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.
February 18, 2013 at 8:43 am #20989brightlaunchMemberThanks cdils... I realized the missing colon! Just revised my post... it's mostly working, but the scripts still show up on the category pages itself… I only want it to show for the posts in those categories…
February 18, 2013 at 9:16 am #20996cdilsParticipantYou might need to check usage between is_category vs in_category (http://codex.wordpress.org/Conditional_Tags)
For instance, you don't want it to show if it is_category('category-id) && if it's in_category('post-id').
Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂
I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.
February 18, 2013 at 10:21 am #21014brightlaunchMemberOk, I figured it out.... needed || instead of &&:
add_action('wp_print_styles', 'custom_show_zlrecipe');
function custom_show_zlrecipe() {
if (is_category() || !in_category (array ('11','284','285','288','289','291','292','293','294','295','296','270','273','274','275','279','280','282','283'))) {
remove_filter('wp_head', 'amd_zlrecipe_process_head');
}
} -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.