Skip to content

Commit 59e7133

Browse files
committed
Header/Footer: Link homepage to root site URL on Rosetta sites.
See #49
1 parent 51399a8 commit 59e7133

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

mu-plugins/blocks/global-header-footer/blocks.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,33 @@ function normalize_rosetta_items( $rosetta_items ) {
354354
return $normalized_items;
355355
}
356356

357+
/**
358+
* Retrieve the URL of the home page.
359+
*
360+
* Most of the time it will just be `w.org/`, but Rosetta sites use the URL of the "root site" homepage.
361+
*/
362+
function get_home_url() {
363+
/** @var Rosetta_Sites $rosetta */
364+
global $rosetta;
365+
366+
$url = false;
367+
368+
if ( is_rosetta_site() ) {
369+
$root_site = $rosetta->get_root_site_id();
370+
switch_to_blog( $root_site );
371+
372+
$url = home_url();
373+
374+
restore_current_blog();
375+
}
376+
377+
if ( ! $url ) {
378+
$url = 'https://wordpress.org/';
379+
}
380+
381+
return $url;
382+
}
383+
357384
/**
358385
* Retrieve the URL to download WordPress.
359386
*

mu-plugins/blocks/global-header-footer/header.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
namespace WordPressdotorg\MU_Plugins\Global_Header_Footer\Header;
4-
use function WordPressdotorg\MU_Plugins\Global_Header_Footer\{ get_download_url };
4+
use function WordPressdotorg\MU_Plugins\Global_Header_Footer\{ get_home_url, get_download_url };
55

66
defined( 'WPINC' ) || die();
77

@@ -18,15 +18,15 @@
1818
<!-- The design calls for two logos, a small "mark" on mobile/tablet, and the full logo for desktops. -->
1919
<!-- wp:image {"width":27,"height":27,"className":"global-header__wporg-logo-mark"} -->
2020
<figure class="wp-block-image is-resized global-header__wporg-logo-mark">
21-
<a href="https://wordpress.org/">
21+
<a href="<?php echo esc_url( get_home_url() ); ?>">
2222
<img src="https://wordpress.org/style/images/w-mark.svg" alt="WordPress.org" width="27" height="27" />
2323
</a>
2424
</figure>
2525
<!-- /wp:image -->
2626

2727
<!-- wp:image {"width":160,"height":24,"className":"global-header__wporg-logo-full"} -->
2828
<figure class="wp-block-image is-resized global-header__wporg-logo-full">
29-
<a href="https://wordpress.org/">
29+
<a href="<?php echo esc_url( get_home_url() ); ?>">
3030
<img src="<?php echo plugin_dir_url( __FILE__ ) . 'images/wporg-logo.svg'; ?>" alt="WordPress.org" width="160" height="24" />
3131
</a>
3232
</figure>

0 commit comments

Comments
 (0)