-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Adds the editing capability to the search title. #61508
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @vipul0425! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
@@ -38,13 +38,23 @@ function render_block_core_query_title( $attributes ) { | |||
} | |||
} | |||
if ( $is_search ) { | |||
$title = __( 'Search results' ); | |||
$title = isset( $attributes['searchResultsTerm'] ) && ! empty( $attributes['searchResultsTerm'] ) ? $attributes['searchResultsTerm'] : __( 'Search results' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling isset()
is not needed since empty()
already checks if the property is set. Calling !empty( $attributes['searchResultsTerm'] )
is equivalent to calling isset( $attributes['searchResultsTerm'] ) && $attributes['searchResultsTerm']
.
$title = isset( $attributes['searchResultsTerm'] ) && ! empty( $attributes['searchResultsTerm'] ) ? $attributes['searchResultsTerm'] : __( 'Search results' ); | |
$title = ! empty( $attributes['searchResultsTerm'] ) ? $attributes['searchResultsTerm'] : __( 'Search results' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @anton-vlasenko. I have fixed it in the latest commit 🙇
Thanks, @jameskoster, for pointing this out. I've addressed the inconsistency in the latest commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vipul0425 Thanks for the PR!
I think the important thing here is that the "Archive Title" block and the "Search Results Title" block exist as variations of the block called "Query Title" block. Similarly, the text of the Archive Title block cannot be edited at all.
Is there a request to be able to edit the prefix and suffix text in the Archive Title block as well? If there is, it may be better to avoid adding attribute names that depend on specific variations such as searchResultsTerm
and searchResultsTermSuffix
. More generic attribute names like prefix
and suffix
might be useful if we want to apply this approach to the Archive Title block in the future.
Another important point is that the term "Search Results for:" is not guaranteed to appear before the search term in all languages. For example, in Japanese Search results for "%s"
is translated as 「%s」の検索結果
.
In order to advance this PR, I would be happy if we could have a more detailed discussion and find the ideal approach.
I'll also ping @jorgefilipecosta and @carolinan who have worked on improving this block in the past.
Hi @t-hamano, Thanks for reviewing this. Regarding the "Archive Title," I believe it should be editable, but as there was no request for adding that, I updated only for the Search Title block. I could only find this issue from the past referring to the update in Archive-title #44158. Regarding using generic terms for prefixes and suffixes, do we want to share the same prefix and suffix across the archive and search title like the showPrefix attribute? I think we should keep them separate though we can club both the prefixes (archive and search title) under a common attribute object like "prefix." Let me know what you think about this. Thanks for letting me know about "Search Results for:" in different language scenarios. We can use a generic placeholder value like "prefix." Let me know if you have any better suggestions. Thanks 🙇 |
This sounds like a very good idea! I will update the original issue to reflect a change to both the Search Results Title block and the Archive Title block. |
Sorry for the late reply. I was thinking of an ideal solution to this problem, but it might be more complicated than I thought 😅 What I think is the ideal approach is as follows: The default state of the block has Prefix and suffix placeholders and displays only the search term. Users can reproduce the same title by entering text in Prefix and Suffix. When "Show search term in title" is off, it will display a placeholder with the placeholder "Search results". This is managed internally as the If this approach makes sense, block migration is required to preserve the appearance of existing blocks. We will need to consider the following two patterns: If "Show search term in title" is enabledAssign If "Show search term in title" is disabledAssign What do you think about this approach? |
Hey @t-hamano Aki SearchThis is what I read. An example Default state is when the toggle Show search term in title is on. The Search page will show: Search results for: “course”When the toggle search term in title is off. The Search page will show: Search resultsAdding a Prefix to adjust the Search results / Search results for: “ —> will be very helpful. This means. You are looking for -> is then the Prefix. When the toggle Show search term in title is off. Conclusion. This sounds like a good approach! Archive titleDefault toggle on: Show archive type in title. (Archive type: Name) Example. A category named course. On the frontend it will show Category: course Toggle is off. (Archive title) Since text is automatically inserted when the toggle is on or off. |
That's right. Being able to edit only the text is almost the same as the Paragraph block, so I thought about removing the toggle itself, but this specification is for backward compatibility. Regarding the Archive Title block (variation), it may be a good idea to maintain the current specifications and consider it as a follow-up. |
Here is a similar PR: #61920 It is also working on the prefix / suffix. Similar approaches should be done for both PRs. |
Hi @vipul0425, The approach I suggested, adding the prefix and suffix, may not be ideal. See #61920 for details. Sorry for the confusion 🙏 |
Thanks for the PR! It seems to me we should probably wait a bit for
@t-hamano raised a very good aspect of the block and even made me think what other variations this block could have besides the existing two variations. This block was introduced 3 years ago with only the |
What?
Fixes issue #60701
This PR adds the editing capability to the search results title block.
Why?
How?
richtext
component to make the title editable.Testing Instructions
Testing Instructions for Keyboard
Nil
Screenshots or screencast
compressed.screencast.1.mp4