[Resolved] How do I show the post type description in a post type archive?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Related documentation: Content Templates

This topic contains 3 replies, has 2 voices, and was last updated by  Christian Cox 1 week, 2 days ago. The support staff assigned to this topic is Christian Cox.

Viewing 4 posts - 1 through 4 (of 4 total)
Author
Posts
#559212

Tell us what you are trying to do?
I am trying to show the post type description in a post type archive template. I would like it to be at the top of the page, placed via a custom shortcode, above the loop.
Is there any documentation that you are following?
I've searched your forums and can only find instructions on how to add code to functions.php to show post type descriptions in content templates, not on archive pages. Taxonomy archive descriptions are available as a native shortcode already, but not post type descriptions.
Is there a similar example that we can see?

What is the link to your site?

#559356

Christian Cox
Forum moderator

Supporter languages: English (English )

Supporter Timezone: America/New_York (GMT-04:00)

Hi, you can use the same code, modified slightly for post type archives:

function get_post_desc_for_archive( $atts,$content ) {
    global $wp_post_types;
    global $WP_Views;

    $post_type = $WP_Views->post_query->query['post_type'];
    $obj = $wp_post_types[$post_type];
    return $obj->description;
}
add_shortcode( 'get_cpt_desc_for_archive', 'get_post_desc_for_archive' );

Then the shortcode will be:

[get_cpt_desc_for_archive]
#559531

Works perfectly. Thanks!

#559536

Christian Cox
Forum moderator

Supporter languages: English (English )

Supporter Timezone: America/New_York (GMT-04:00)

Hi, I just noticed that I left in an error_log statement by mistake. I have removed that statement from the code above. This statement can be removed from your code as well. It won't affect your code if you leave it in place, but it may write a message into your server logs.

Viewing 4 posts - 1 through 4 (of 4 total)

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Known issues and their solutions

We document known issues and their solutions in Toolset erratas. Save time by checking there first and seeing if what you are facing is a known issue. This list is kept short. We do our best to resolve all known issues with every release of Toolset plugins.

Support Policy

Toolset staff will help you use the Toolset plugins correctly, provide any information you need, help troubleshoot problems and advice on best-practices.

Please make sure to issue only one topic per each support ticket.

For more information, read our full Customer Support Policy.

Need custom programming work for your site? Check out our certified partners.