Skip to content

Commit

Permalink
Remove breadcrumbs from About and Download subpages
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle committed Jul 7, 2023
1 parent 20c46e9 commit 177e61a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 32 deletions.
57 changes: 44 additions & 13 deletions source/wp-content/themes/wporg-main-2022/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
add_action( 'init', __NAMESPACE__ . '\register_shortcodes' );
add_filter( 'wp_img_tag_add_loading_attr', __NAMESPACE__ . '\override_lazy_loading', 10, 2 );
add_filter( 'wporg_block_site_breadcrumbs', __NAMESPACE__ . '\update_site_breadcrumbs' );
add_filter( 'render_block_core/site-title', __NAMESPACE__ . '\use_parent_page_title', 10, 3 );

/**
* Enqueue scripts and styles.
Expand Down Expand Up @@ -117,29 +118,59 @@ function override_lazy_loading( $value, $image ) {
}

/**
* In the subpages, update first breadcrumb to be the parent page, rather than site home.
* Use the page heirarchy to display breadcrumbs.
*/
function update_site_breadcrumbs( $breadcrumbs ) {
$parent = get_post_parent();
if ( ! $parent ) {
return $breadcrumbs;
}

if ( 'about' === $parent->post_name ) {
$top_level_page = array(
'url' => home_url( '/about/' ),
'title' => __( 'About', 'wporg' ),
);
$breadcrumbs[0] = $top_level_page;
} else if ( 'download' === $parent->post_name ) {
$top_level_page = array(
'url' => home_url( '/download/' ),
'title' => __( 'Download', 'wporg' ),
$breadcrumbs = array();
$breadcrumbs[] = array(
'url' => false,
'title' => get_the_title(),
);

while ( $parent ) {
$breadcrumbs[] = array(
'url' => get_permalink( $parent->ID ),
'title' => $parent->post_title,
);
$breadcrumbs[0] = $top_level_page;
$parent = get_post_parent( $parent );
}

return array_reverse( $breadcrumbs );
}

/**
* Replace the site title & link with the parent page title.
*
* The About and Download sections are pseudo-individual sites, so when site title
* is used there, it should reference the parent page.
*
* @param string $block_content The block content.
* @param array $block The full block, including name and attributes.
* @param WP_Block $instance The block instance.
*/
function use_parent_page_title( $block_content, $block, $instance ) {
$parent = get_post_parent();
if ( ! $parent ) {
return $block_content;
}

// Loop up to the first child page, this is the section title.
while ( $parent ) {
$url = get_permalink( $parent->ID );
$title = $parent->post_title;
$parent = get_post_parent( $parent );
}

return $breadcrumbs;
return str_replace(
array( home_url(), get_bloginfo( 'name' ) ),
array( $url, $title ),
$block_content
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
*/

?>
<!-- wp:wporg/local-navigation-bar {"backgroundColor":"white","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"16px","bottom":"16px"}},"position":{"type":"sticky"},"elements":{"link":{"color":{"text":"var:preset|color|charcoal-1"},":hover":{"color":{"text":"var:preset|color|charcoal-1"}}}},"border":{"top":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"right":{},"bottom":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"left":{}}},"textColor":"charcoal-1","fontSize":"small"} -->
<!-- wp:wporg/local-navigation-bar {"backgroundColor":"white","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"16px","bottom":"16px"}},"position":{"type":"sticky"},"border":{"top":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"right":{},"bottom":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"left":{}}},"textColor":"charcoal-1","fontSize":"small"} -->
<!-- wp:site-title {"level":0,"fontSize":"small"} /-->

<!-- wp:navigation {"ref":16892,"textColor":"blueberry-1","hasIcon":false,"layout":{"type":"flex","orientation":"horizontal"},"fontSize":"small"} /-->
<!-- /wp:wporg/local-navigation-bar -->

<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"16px","bottom":"16px"}}},"fontSize":"small"} -->
<div class="wp-block-group alignfull has-small-font-size" style="padding-top:16px;padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:16px;padding-left:var(--wp--preset--spacing--edge-space)"><!-- wp:wporg/site-breadcrumbs /--></div>
<!-- /wp:group -->
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
*/

?>
<!-- wp:wporg/local-navigation-bar {"backgroundColor":"white","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"16px","bottom":"16px"}},"position":{"type":"sticky"},"elements":{"link":{"color":{"text":"var:preset|color|charcoal-1"},":hover":{"color":{"text":"var:preset|color|charcoal-1"}}}},"border":{"top":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"right":{},"bottom":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"left":{}}},"textColor":"charcoal-1","fontSize":"small"} -->
<!-- wp:wporg/local-navigation-bar {"backgroundColor":"white","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"16px","bottom":"16px"}},"position":{"type":"sticky"},"border":{"top":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"right":{},"bottom":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"left":{}}},"textColor":"charcoal-1","fontSize":"small"} -->
<!-- wp:site-title {"level":0,"fontSize":"small"} /-->

<!-- wp:navigation {"ref":17028,"textColor":"blueberry-1","hasIcon":false,"layout":{"type":"flex","orientation":"horizontal"},"fontSize":"small"} /-->
<!-- /wp:wporg/local-navigation-bar -->

<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"16px","bottom":"16px"}}},"fontSize":"small"} -->
<div class="wp-block-group alignfull has-small-font-size" style="padding-top:16px;padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:16px;padding-left:var(--wp--preset--spacing--edge-space)"><!-- wp:wporg/site-breadcrumbs /--></div>
<!-- /wp:group -->
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
*/

?>
<!-- wp:wporg/local-navigation-bar {"backgroundColor":"white","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"16px","bottom":"16px"}},"position":{"type":"sticky"},"elements":{"link":{"color":{"text":"var:preset|color|charcoal-1"},":hover":{"color":{"text":"var:preset|color|charcoal-1"}}}},"border":{"top":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"right":{},"bottom":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"left":{}}},"textColor":"charcoal-1","fontSize":"small"} -->
<!-- wp:wporg/local-navigation-bar {"backgroundColor":"white","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"16px","bottom":"16px"}},"position":{"type":"sticky"},"border":{"top":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"right":{},"bottom":{"color":"var:preset|color|light-grey-1","style":"solid","width":"1px"},"left":{}}},"textColor":"charcoal-1","fontSize":"small"} -->
<!-- wp:site-title {"level":0,"fontSize":"small"} /-->

<!-- wp:navigation {"ref":16421,"textColor":"blueberry-1","hasIcon":false,"layout":{"type":"flex","orientation":"horizontal"},"fontSize":"small"} /-->
<!-- /wp:wporg/local-navigation-bar -->

<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"16px","bottom":"16px"}}},"fontSize":"small"} -->
<div class="wp-block-group alignfull has-small-font-size" style="padding-top:16px;padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:16px;padding-left:var(--wp--preset--spacing--edge-space)"><!-- wp:wporg/site-breadcrumbs /--></div>
<!-- /wp:group -->
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@

<!-- wp:navigation {"ref":11576,"hasIcon":false,"layout":{"type":"flex","orientation":"horizontal"},"fontSize":"small"} /-->
<!-- /wp:wporg/local-navigation-bar -->

<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"right":"var:preset|spacing|edge-space","left":"var:preset|spacing|edge-space","top":"32px","bottom":"16px"}}},"fontSize":"small"} -->
<div class="wp-block-group alignfull has-small-font-size" style="padding-top:32px;padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:16px;padding-left:var(--wp--preset--spacing--edge-space)"><!-- wp:wporg/site-breadcrumbs /--></div>
<!-- /wp:group -->

0 comments on commit 177e61a

Please sign in to comment.