| @@ -16,15 +16,41 @@ | ||
| 16 | 16 | */ |
| 17 | 17 | function gutenberg_render_block_core_query_title( $attributes ) { |
| 18 | 18 | $type = isset( $attributes['type'] ) ? $attributes['type'] : null; |
| 19 | 19 | $is_archive = is_archive(); |
| 20 | - if ( ! $type || ( 'archive' === $type && ! $is_archive ) ) { | |
| 20 | + $is_search = is_search(); | |
| 21 | + if ( ! $type || | |
| 22 | + ( 'archive' === $type && ! $is_archive ) || | |
| 23 | + ( 'search' === $type && ! $is_search ) | |
| 24 | + ) { | |
| 21 | 25 | return ''; |
| 22 | 26 | } |
| 23 | 27 | $title = ''; |
| 24 | 28 | if ( $is_archive ) { |
| 25 | - $title = get_the_archive_title(); | |
| 29 | + $show_prefix = isset( $attributes['showPrefix'] ) ? $attributes['showPrefix'] : true; | |
| 30 | + if ( ! $show_prefix ) { | |
| 31 | + $filter_title = function( $title, $original_title ) { | |
| 32 | + return $original_title; | |
| 33 | + }; | |
| 34 | + add_filter( 'get_the_archive_title', $filter_title, 10, 2 ); | |
| 35 | + $title = get_the_archive_title(); | |
| 36 | + remove_filter( 'get_the_archive_title', $filter_title, 10, 2 ); | |
| 37 | + } else { | |
| 38 | + $title = get_the_archive_title(); | |
| 39 | + } | |
| 26 | 40 | } |
| 41 | + if ( $is_search ) { | |
| 42 | + $title = __( 'Search results' ); | |
| 43 | + | |
| 44 | + if ( isset( $attributes['showSearchTerm'] ) && $attributes['showSearchTerm'] ) { | |
| 45 | + $title = sprintf( | |
| 46 | + /* translators: %s is the search term. */ | |
| 47 | + __( 'Search results for: "%s"' ), | |
| 48 | + get_search_query() | |
| 49 | + ); | |
| 50 | + } | |
| 51 | + } | |
| 52 | + | |
| 27 | 53 | $tag_name = isset( $attributes['level'] ) ? 'h' . (int) $attributes['level'] : 'h1'; |
| 28 | 54 | $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; |
| 29 | 55 | $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); |
| 30 | 56 | return sprintf( |