Site logo

Archived topic

Help create a shortcode to output current Archive title+description

9 replies · Started by tractor-1 on July 21, 2020

Viewing posts 1–10 of 10

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

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

You could try this:

add_shortcode( 'taxonomy_title_description', function() {
    ob_start();

    generate_archive_title();

    return ob_get_clean();
} );

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.

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.

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.

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 );

All set now, thank you GP support!

Glad we could help! :)

This archived topic is closed to new replies.