generated from pascalmartineau/wp-skeleton
feat: Virtual page redirect, breadcrumb & menu items
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 1m5s
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 1m5s
This commit is contained in:
18
wp-content/themes/ccat/includes/core/virtual-page.php
Normal file
18
wp-content/themes/ccat/includes/core/virtual-page.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
// Helper: Determine if page is a virtual page
|
||||
function ccat_is_virtual_page( $page_id ) {
|
||||
return get_post_meta( $page_id, '_wp_page_template', true ) === 'virtual.php';
|
||||
}
|
||||
|
||||
// Replace menu item path with '#' for virtual pages
|
||||
add_filter( 'graphql_resolve_field', 'ccat_virtual_page_menu_item_graphql_value', 10, 5 );
|
||||
function ccat_virtual_page_menu_item_graphql_value( $result, $source, $args, $context, $info ) {
|
||||
if ( $source instanceof \WPGraphQL\Model\MenuItem && $info->fieldName === 'path' ) {
|
||||
$menu_item = wp_setup_nav_menu_item( get_post( $source->databaseId ) );
|
||||
if ( $menu_item->object === 'page' && ccat_is_virtual_page( $menu_item->object_id ) ) {
|
||||
return '#';
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
Reference in New Issue
Block a user