Created
February 20, 2020 12:30
-
-
Save herewithme/b4b8d7a69d5a3ed72764238528284794 to your computer and use it in GitHub Desktop.
Add jobs listing page on rankMath breadcrumb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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