Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions themes/osi/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
7 changes: 6 additions & 1 deletion themes/osi/header-ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@
);
endif;
?>
<a class="nav-main--cta" href="<?php echo esc_url( home_url( '/get-involved/' ) ); ?>"><?php esc_html_e( 'Get Involved', 'osi' ); ?></a>
<?php
$osi_cta = osi_menu_cta();
if ( null !== $osi_cta ) {
echo '<a class="nav-main--cta" href="' . esc_url( $osi_cta['url'] ) . '"' . ( $osi_cta['target'] ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>' . esc_html( $osi_cta['label'] ) . '</a>';
}
?>
</nav><!-- #site-navigation -->

<section class="open-button-wrapper">
Expand Down
7 changes: 6 additions & 1 deletion themes/osi/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@
);
endif;
?>
<a class="nav-main--cta" href="<?php echo esc_url( home_url( '/get-involved/' ) ); ?>"><?php esc_html_e( 'Get Involved', 'osi' ); ?></a>
<?php
$osi_cta = osi_menu_cta();
if ( null !== $osi_cta ) {
echo '<a class="nav-main--cta" href="' . esc_url( $osi_cta['url'] ) . '"' . ( $osi_cta['target'] ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>' . esc_html( $osi_cta['label'] ) . '</a>';
}
?>
</nav><!-- #site-navigation -->
<section class="open-search-wrapper">
<a aria-label="Open Search" class="open-search open-button jetpack-search-filter__link" href="#">
Expand Down
63 changes: 63 additions & 0 deletions themes/osi/inc/menu-cta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Mobile menu CTA: field registration + resolution.
*
* @package osi
*/

add_action( 'acf/include_fields', 'osi_menu_cta_field' );
/**
* Register the CTA link field shown on the primary menu's settings in Appearance > 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'] ),
);
}
Loading