[Resolved] Help create a shortcode to output current Archive title+description

Home Forums Support [Resolved] Help create a shortcode to output current Archive title+description

Home Forums Support Help create a shortcode to output current Archive title+description

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1371110
    tractor-1

    Hi,

    I need to move the Woocommerce archive/category/tag/search etc title and description to the left and thought it would be possible through a shortcode put in a widget in the left sidebar. Demo.

    Also, I’d like it to come wrapped in an aside tag with an id and a class so I can style it.

    Thank you

    #1371179
    Leo
    Staff
    Customer Support

    Hi there,

    This is something you will need to check with WooCommerce’ support.

    Perhaps a post like this would help?
    https://wordpress.org/support/topic/short-codes-for-category-display/

    #1371263
    tractor-1

    Okay, ignore Woocommerce, how to output the post category/tag/search results/archive title and description through a shortcode?

    #1371414
    Tom
    Lead Developer
    Lead Developer

    You could try this:

    add_shortcode( 'taxonomy_title_description', function() {
        ob_start();
    
        generate_archive_title();
    
        return ob_get_clean();
    } );
    #1371936
    tractor-1

    Simple, clean and beautiful — and works like a charm for Woocommerce archives too.

    Any way to filter out the prefixes “Category:” and “Tag:” from the title on the product category and tag pages?

    Post category and tag archives don’t have these prefixes in the title already, which is awesome.

    #1372019
    David
    Staff
    Customer Support

    Hi there,

    try this:

    add_shortcode( 'taxonomy_title_description' , 'db_woo_archive_entry_header' );
    
    function db_woo_archive_entry_header() {
      ob_start();
      if ( is_product_category() ) {
          add_filter( 'woocommerce_show_page_title', '__return_false' );
          remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
          $term_object = get_queried_object();
          ?>
          <div class="woocommerce-category-description">
              <div class="inside-article">
                  <h1 class="title"><?php echo $term_object->name; ?></h1>
                  <div class="description"><?php echo $term_object->description; ?></div>
              </div>
          </div>
          <?php
        }
        return ob_get_clean();    
    }

    Original topic it came from for reference:
    https://generatepress.com/forums/topic/shop-description-to-match-blog-category-description/#post-634945

    You may want to modify the markup and remove the Description to suit.

    #1372471
    tractor-1

    The code seems to work except for the

    add_filter( 'woocommerce_show_page_title', '__return_false' );
    remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );

    part as both the title and the description are still showing in their original location in the entry content area too.

    #1372704
    Tom
    Lead Developer
    Lead Developer

    You may need to put that in a different hook:

    add_action( 'wp', function() {
        add_filter( 'woocommerce_show_page_title', '__return_false' );
        remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
    }, 100 );
    #1372730
    tractor-1

    All set now, thank you GP support!

    #1373761
    Tom
    Lead Developer
    Lead Developer

    Glad we could help! 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.