- This topic has 7 replies, 4 voices, and was last updated 3 years, 10 months ago by
Fernando.
-
AuthorPosts
-
May 31, 2022 at 10:09 am #2239456
Sascha
Hi,
please, allow me to handle this request here, since I use both GPP & GBP and would like to keep all my support tickets here.
I two CPTs “Academy” & “Support”.
Now I want to hook the Name of the CPT on top of the post-title dynamically.
So when a visitor opens the post “How to learn french?” (Academy post), the name “Academy” will be placed between the header & the post-title.
I have created a block-hook element “after_header” and added a GBP-headline-block, which will be visible on all single posts of these two CPTs.
How can I use this headline to display the current CPT-name?
Thank you in advance and kind regards,
SaschaMay 31, 2022 at 11:24 am #2239529Ying
StaffCustomer SupportHi Sascha,
The post type name is not a regular value that you can simply call using a headline block.
Try this function and use this shortcode:
[post_type_name]add_shortcode('post_type_name',function() { ob_start(); $post = get_queried_object(); $postType = get_post_type_object(get_post_type($post)); if ($postType) { echo esc_html($postType->labels->singular_name); } return ob_get_clean(); });You can use a hook element and tick the execute shortcode box, or use a block element, add the shortcode into a shortcode block.
June 1, 2022 at 12:24 am #2239918Sascha
Thanks Ying,
I have added the code via Code Snippet and added the shortcode in Elements, as you can see on this screenshot. Here you can see the Element Type “Block Hook”.
But the archive-title is still not visible, as you can see here & here.
Can you please help me further?
Thank you in advance and kind regards,
SaschaJune 1, 2022 at 1:36 am #2239979Fernando Customer Support
Hi Sascha,
Can you try modifying the shortcode to something like this instead?
add_shortcode('post_type_name',function() { ob_start(); global $post; $postType = get_post_type_object(get_post_type($post)); if ($postType) { echo esc_html($postType->labels->singular_name); } return ob_get_clean(); });Kindly let us know how it goes.
June 1, 2022 at 4:23 am #2240104Sascha
Hi Fernando, thanks a lot, I have replaced the previous shortcode with the one you have provided, but nothing has changed. Caching was disabled.
June 1, 2022 at 5:45 am #2240191David
StaffCustomer SupportHi there,
i see this on your single post:
https://www.screencast.com/t/VhCCrrE3lEr
Is that not correct ?
June 2, 2022 at 12:24 am #2241004Sascha
Sorry, some confusion here 🙈 I have two issues:
1. CTP Archive Page: How to Replace the “Archive:Academy” title with a custom title, which includes the Custom Post Type Name “Academy” dynamically?
Example of the title for the CTP “Academy”: “Academy Overview” instead of “Archive:Academy”
Example of the title for the CTP “Support”: “Support Articles” instead of “Archive:Support”2. CTP Single Pages: Currently, I have added a breadcrumb via the shortcode [seopress_breadcrumbs]. I wonder if GP or GB (have Pro for both) can help me to remove the single-post-title from the breadcrumb?
Thank you in advance and kind regards,
SaschaJune 2, 2022 at 2:33 am #2241136Fernando Customer Support
1. The shortcode above allows you to retrieve the Post type. You can use a Block Element – Page Hero, then display the post type dynamically by adding a Shortcode Block with shortcode – [post_type_name].
So we can modify the shortcode so that it conditionally checks the post type to display the subtitle as well:
add_shortcode('post_type_name',function() { ob_start(); global $post; $postType = get_post_type_object(get_post_type($post)); if ($postType) { if( 'Academy' === $postType->labels->singular_name) { echo '<h1 class="my-cpt-class">' . $postType->labels->singular_name . ' - Academy Overview</h1>'; } else if( 'Support' === $postType->labels->singular_name) { echo '<h1 class="my-cpt-class">' . $postType->labels->singular_name . ' - Support Articles</h1>'; } } return ob_get_clean(); });Sample usage: https://share.getcloudapp.com/kpu8y1Qq
Alternatively, you can also create two Block Elements – Page Hero for each CPT archive page.
2. I believe you can modify this in Yoast settings. See: https://yoast.com/help/the-breadcrumbs-title-setting/
Hope this clarifies!
-
AuthorPosts
- You must be logged in to reply to this topic.