Created
September 25, 2017 18:34
-
-
Save jaygidwitz/49fc125600a7db5424028f0ad3c9b26d to your computer and use it in GitHub Desktop.
MonsterInsights logout
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
/** | |
* 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