• Hello,

    Basically I am making a website for a local shop using wordpress and woocommerce. They want a different background to be used on two of the categories, Which should be very straight forward…
    But, for some reason, it’s deciding not to function as it should. I have tried using the woocommerce documentation, but quite frankly it’s worthless (tells me nothing about how to use the parameters) so I attempted to use it just as the wordpress is_category. I have also tried using is_category.

    The problem is, it isn’t registering any of my parameters. All it is doing is the basic is_category() function. I have tried using the name, slug and ID all without success.

    <?php if (is_product_category( 'legal-highs' )) : ?>
     <style type="text/css">
     	#wrapper {background-image:url(https://streetwiseheadshop.co.uk/wp-content/themes/streetwise2/images/background2.jpg) !important;}
    </style>
    <?php endif; ?>

    This is the code I’m using (obviously change is_product_category to is_category, it makes no difference so far…

    What am I doing wrong?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Something like:

    <?php if (is_category() :
    	global $cat; //$cat = WordPress global holds the category->ID
    	if ($cat == 4 || $cat == 16 ) :
    	?>
    		<style type="text/css">
    			#wrapper {background-image:url(https://streetwiseheadshop.co.uk/wp-content/themes/streetwise2/images/background2.jpg) !important;}
    		</style>
    	<?php
    	endif;
    endif; ?>

    HTH

    David

    Thread Starter ParadoxDev

    (@paradoxdev)

    Unfortunately that does absolutely nothing, no changes at all :/

    Where are you adding the code, and you did change the 4 and 16 to match your catergory->ID?

    The code could be in header.php inside the <head> </head> tags, or in a function in functions.php with an action to run it!

    Example:

    function my_background_style() {
    	if (is_category() {
    		global $cat; //$cat = WordPress global holds the category->ID
    		if ($cat == 4 || $cat == 16 ) { ?>
    			<style type="text/css">
    				#wrapper {background-image:url(https://streetwiseheadshop.co.uk/wp-content/themes/streetwise2/images/background2.jpg) !important;}
    			</style>
      <?php
    		}
    	}
    }
    add_action( 'wp_head', 'my_background_style' );

    HTH

    David

    Thread Starter ParadoxDev

    (@paradoxdev)

    Sorry for the very late reply, this wasn’t as high priority as other things so was left for a while.

    I have the code in my <head> tags, just under wp_head(),

    <?php if (is_category()) :
    	global $cat;
    	if ($cat == 42) :
    	?>
    		<style type="text/css">
    			#wrapper {background-image:url(https://streetwiseheadshop.co.uk/wp-content/themes/streetwise2/images/background2.jpg) !important;}
    		</style>
    	<?php
    	endif;
    endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘If is_category issues’ is closed to new replies.