Problem: I would like to display the description of a custom post type in the archive of that custom post type. The shortcode I found for non-archive pages does not work on archives.
Solution: Add the following code to functions.php to enable a shortcode on archive pages:
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' );
Use the shortcode on archive pages like this:
[get_cpt_desc_for_archive]
Relevant Documentation: https://codex.wordpress.org/Shortcode_API
https://codex.wordpress.org/Function_Reference/get_post_type_object
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 3 replies, has 2 voices.
Last updated by 7 years, 3 months ago.
Assisted by: Christian Cox.