Skip to content

Instantly share code, notes, and snippets.

@jaygidwitz
Created September 25, 2017 18:34
Show Gist options
  • Save jaygidwitz/49fc125600a7db5424028f0ad3c9b26d to your computer and use it in GitHub Desktop.
Save jaygidwitz/49fc125600a7db5424028f0ad3c9b26d to your computer and use it in GitHub Desktop.
MonsterInsights logout
/**
* Defines a logout link for a WP nav menu item, if that menu item has href="{someurl}?logout=1"
*
* @param array $items Menu Items
* @param array $args Arguments
* @return items Menu Items
*/
function monsterinsights_logout_links( $items, $args ) {
if ( ! empty( $items ) && is_array( $items ) ) {
foreach( $items as $key => $item ){
if ( strpos( $item->url, '?logout=1' ) === false ) {
continue;
}
$items[$key]->url = str_replace( '//', '/', str_replace( '&', '&', wp_logout_url( trailingslashit( site_url() ) . str_replace( '?logout=1', '', $item->url ) ) ) );
}
}
return $items;
}
add_filter( 'wp_nav_menu_objects', 'monsterinsights_logout_links', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment