Archived topic
Search Page Customisations
5 replies · Started by Matt on December 9, 2021
Hi Guys,
I just have a couple of questions around search results page.
1. Header Element. I have a block element with dynamic Header Block. Rather than showing the search result page title ie. 'Search result: example', the dynamic header is populated with the title of the first returned post. Am i doing something wrong here?
2. Content Template for search result item. I have several post types (custom) and also regular posts and pages being returned in the search results. Can the dynamic text options be configured to populate the type of result? ie. 'Page', "post", 'custom post type 1'... So for each search result the user can see if it is a page, a post, a custom post type etc?
Thanks
Hi Matt,
1. You are not doing something wrong, it's the normal behavior as search result page doesn't really have a title. So the dynamic block can't pull the title, instead it pulls the title of the first search result.
2. I don't think so Unfortuanly.
Would it be possible to use a shortcode or something to place the post type name in a content template?
You can give this PHP snippet a try:
add_shortcode( 'show_post_type', 'custom_show_post_type' );
function custom_show_post_type() {
$postType = get_post_type_object(get_post_type());
if ($postType) {
return esc_html($postType->labels->singular_name);
}
}
Then use [show_post_type] as the shortcode.
That's perfect.. Thankyou!
You are welcome :)