diff --git a/themes/osi/functions.php b/themes/osi/functions.php index 3be3513..698093b 100755 --- a/themes/osi/functions.php +++ b/themes/osi/functions.php @@ -294,6 +294,11 @@ function osi_add_block_editor_assets() { */ require get_template_directory() . '/inc/megamenu-featured.php'; +/** + * Mobile menu CTA field. + */ +require get_template_directory() . '/inc/menu-cta.php'; + /** * Color functions. */ diff --git a/themes/osi/header-ai.php b/themes/osi/header-ai.php index 0f0442a..77d8e15 100755 --- a/themes/osi/header-ai.php +++ b/themes/osi/header-ai.php @@ -50,7 +50,12 @@ ); endif; ?> - + ' . esc_html( $osi_cta['label'] ) . ''; + } + ?>
diff --git a/themes/osi/header.php b/themes/osi/header.php index 79406b3..9a933dd 100755 --- a/themes/osi/header.php +++ b/themes/osi/header.php @@ -61,7 +61,12 @@ ); endif; ?> - + ' . esc_html( $osi_cta['label'] ) . ''; + } + ?>
diff --git a/themes/osi/inc/menu-cta.php b/themes/osi/inc/menu-cta.php new file mode 100644 index 0000000..e19ee98 --- /dev/null +++ b/themes/osi/inc/menu-cta.php @@ -0,0 +1,63 @@ + Menus. + * + * @return void + */ +function osi_menu_cta_field() { + acf_add_local_field_group( + array( + 'key' => 'group_osi_menu_cta', + 'title' => __( 'Mobile menu CTA', 'osi' ), + 'label_placement' => 'top', + 'fields' => array( + array( + 'key' => 'field_osi_menu_cta_link', + 'label' => __( 'CTA link', 'osi' ), + 'name' => 'osi_menu_cta_link', + 'type' => 'link', + 'instructions' => __( 'Bottom button of the mobile menu only. Empty = no button.', 'osi' ), + 'return_format' => 'array', + ), + ), + 'location' => array( + array( + array( + 'param' => 'nav_menu', + 'operator' => '==', + 'value' => 'location/primary_navigation', + ), + ), + ), + ) + ); +} + +/** + * Resolve the mobile menu CTA; no field value means no button. + * + * @return array|null Array with 'url', 'label' and 'target' (boolean) keys, or null. + */ +function osi_menu_cta() { + $locations = get_nav_menu_locations(); + $menu = function_exists( 'get_field' ) ? wp_get_nav_menu_object( $locations['primary_navigation'] ?? 0 ) : false; + $link = $menu ? (array) get_field( 'osi_menu_cta_link', $menu ) : array(); + $url = ! empty( $link['url'] ) ? esc_url_raw( $link['url'] ) : ''; + + if ( '' === $url ) { + return null; + } + + return array( + 'url' => $url, + 'label' => ! empty( $link['title'] ) ? $link['title'] : __( 'Get Involved', 'osi' ), + 'target' => ! empty( $link['target'] ), + ); +}