Skip to content

Instantly share code, notes, and snippets.

@herewithme
Created February 20, 2020 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herewithme/b4b8d7a69d5a3ed72764238528284794 to your computer and use it in GitHub Desktop.
Save herewithme/b4b8d7a69d5a3ed72764238528284794 to your computer and use it in GitHub Desktop.
Add jobs listing page on rankMath breadcrumb
<?php
/*
Plugin Name: RankMath & WP Job Manager
Version: 1.0.0
Plugin URI: https://beapi.fr
Description: Add jobs listing page on rankMath breadcrumb
Author: Be API
Author URI: https://beapi.fr
*/
/**
* Add jobs listing page on rankMath breadcrumb
*
* @param array $crumbs The crumbs array.
* @param Breadcrumbs $this Current breadcrumb object.
*/
add_filter( 'rank_math/frontend/breadcrumb/items', function ( $crumbs, $class ) {
if ( ! is_singular( 'job_listing' ) ) {
return $crumbs;
}
$jobs_page_id = (int) get_option( 'job_manager_jobs_page_id' );
$jobs_page = get_post( $jobs_page_id );
if ( empty( $jobs_page ) || is_wp_error( $jobs_page ) ) {
return $crumbs;
}
$home_obj = array_shift( $crumbs );
array_unshift(
$crumbs,
array(
0 => $jobs_page->post_title,
1 => get_permalink( $jobs_page ),
'hide_in_schema' => false,
)
);
array_unshift( $crumbs, $home_obj );
return $crumbs;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment