skip to Main Content

I am trying to upgrade my SEO on my webshop. Anyone knows php could fix this puzzle. How can i fit this in each other?

How does this: is_product_category( 'shirts' ) fit in this:

function woa_content_before_shop() {
    echo "<p>Insert your Content here...</p>";
}

add_action( 'woocommerce_before_shop_loop', 'woa_content_before_shop');

2

Answers


  1. WordPress conditional tags like is_product_category() can be used to change the displayed content based on the matched condition.

    In this case you can use them to change the printed text based on category. You can exploit them in this way:

    function woa_content_before_shop()
    {
      if ( is_product_category( 'shirts' ) )
      {
        echo "<p>Here are shirts!</p>";
      } 
      else if ( is_product_category( 'games' ) )
      {
        echo "<p>Here are games!</p>";
      } 
      else
      {
        ...
      }
    }
    
    add_action( 'woocommerce_before_shop_loop', 'woa_content_before_shop');
    
    Login or Signup to reply.
  2. Use this code. Also set your descriptions in Products > Categories.

    function woa_content_before_shop() {
        if ( is_product_category() ) {
            global $wp_query;
            $id = $wp_query->get_queried_object_id();
            $desc = term_description( $id, 'product_cat' );
            if ( !empty( $desc ) ) {
                $output = '<p>' . esc_html( $desc ) . '</p>';
                echo $output;
            }
        }
    }
    add_action( 'woocommerce_before_shop_loop', 'woa_content_before_shop');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search