Repository navigation
Help/About: Translate /random slug displayed in graphic. - #16278
peterwilsoncc wants to merge 9 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Caution
While this file is included in the PR, it is not merge ready. The image will be published on w.org's CDN.
| <img loading="lazy" src="https://s.w.org/images/core/7.2/about-feature-02.webp?ver=20261123" alt="" height="900" width="900" /> | ||
| <div class="about__image about__image-random"> | ||
| <img loading="lazy" src="<?php echo esc_url( admin_url( 'images/about-feature-02.webp?ver=20261126' ) ); ?>" alt="" height="900" width="900" /> | ||
| <a class="about__image-random-url" href="<?php echo esc_url( home_url( '/?random' ) ); ?>"> |
There was a problem hiding this comment.
I am not convinced this needs to be a link.
I'm tempted to remove it and hide the entire block from screen readers as it doesn't provide any information that is not in the text.
| $random_path = $wp_rewrite->using_permalinks() ? '/' . "\u{2060}" . _x( 'random', 'random content permalink base' ) : '/?random'; | ||
| $random_url = $wp_rewrite->using_permalinks() ? home_url( user_trailingslashit( $wp_rewrite->root . $wp_rewrite->get_random_base() ) ) : home_url( '/?random' ); |
There was a problem hiding this comment.
The displayed path uses _x() in the current user's locale, while $random_url uses get_random_base(), which returns the custom wp_random_base option if set, and otherwise the default translated into the site locale. With a different user locale or a custom base, the pill and link text can show /random while the link points to another slug. Using the base for both keeps them in sync:
| $random_path = $wp_rewrite->using_permalinks() ? '/' . "\u{2060}" . _x( 'random', 'random content permalink base' ) : '/?random'; | |
| $random_url = $wp_rewrite->using_permalinks() ? home_url( user_trailingslashit( $wp_rewrite->root . $wp_rewrite->get_random_base() ) ) : home_url( '/?random' ); | |
| $random_base = $wp_rewrite->get_random_base(); | |
| $random_path = $wp_rewrite->using_permalinks() ? '/' . "\u{2060}" . $random_base : '/?random'; | |
| $random_url = $wp_rewrite->using_permalinks() ? home_url( user_trailingslashit( $wp_rewrite->root . $random_base ) ) : home_url( '/?random' ); |
The translator comment above would then no longer be needed, since the string is already translated in WP_Rewrite::get_random_base().
This modifies the graphic of the About page's feature image for random redirects to display the URL
/randomin the site's language.The pill displaying the URL is removed from the image and replaced with a text element and an SVG of the link icon. In order to avoid the need to embed Inter with all the non-latin variations, the link is displayed with the font stack:
Inter, Roboto, "Helvetica Neue", "Arial Nova", "Nimbus Sans", Arial, sans-serif;.At the moment the pill is displayed as a link but I may end up removing this as I don't know that it's entirely necessary.
I've created a code bin for testing the display in various languages.
Trac ticket: https://core.trac.wordpress.org/ticket/66202
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Drafting the HTML/CSS for the translatable URL pill and its RTL styles, converting the design's pixel values to container query units, cross-browser and font-fallback testing with screenshots, and building the CodePen-style demo. The design decisions were mine. I reviewed and tested the final code.