congrats, you got most of it right!
But I suggest you check out the wp_logout_url()
function. That’s the proper way to log out WP. This function returns the URL that allows the user to log out of your site. It will handle the nonce creation for you, so you don’t need to worry about that.
Modifying your code to handle that is pretty easy, here’s an example :
function change_menu($items){
foreach($items as $item){
if( $item->title == "Logout"){
$redirect_url="https://google.com"; // your custom redirect URL
$item->url = wp_logout_url($redirect_url);
}
}
return $items;
}
add_filter('wp_nav_menu_objects', 'change_menu');
Here, the wp_logout_url($redirect_url) function will create a correct URL for logging out, and then redirecting to the $redirect_url which you specify. This should help avoid the logout confirmation page.
Related Posts:
- Issues with title-tag and document_title_parts
- Define custom Page Template without its own .php file
- How to influence the information displayed on widget inside wp-admin
- Extract image from content and set it as the featured image
- Is there a hook or function I can use to display all theme files being used on a current page?
- Issue with get_theme_mod returning a blank value instead of the saved value
- Add action hook conditionally – only when home.php in use
- Show modified time if post is actually modified
- why doesnt is_home() work in functions.php
- How to create thumbnails for PDF uploads?
- Implementing DNS Prefetching with WordPress
- How can I tell if I’m on a login page? [duplicate]
- In WooCommerce I need to modify the thankyou.php page [closed]
- Why get_header() or get_footer() does not run twice if called in the same php file?
- Set default options for inserting media
- Change parent theme file function in child themes functions.php
- Adding extra SVGs to TwentyNineteen child theme using class TwentyNineteen_SVG_Icons
- gform_after_submission content appears immediately after , not in post body [closed]
- How do I change parameters without changing the core
- WooCommerce add_action hook results in 500 error
- Issue adding text after short description on product pages Woocommerce [closed]
- Customize “the_posts_pagination” and put list instead div
- Increment price for Woocommerce Minicart [closed]
- how to change link of some wordpress pages
- Gravity Forms field entries into wp_query loop [closed]
- Proper way of using functions in action hook?
- How to preserve edits to Name or Slug of term when using wp_update_term on save?
- Get current page_id before loop, in functions.php
- How to properly add function called by action-hooked function to functions.php?
- Gravity Forms – Using a Form to Pre-populate A Gravity Form [closed]
- Running a script before absolutely everything
- Inserting a functions output after the content
- How to display post content instead of excerpt
- Add function to every post?
- Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘greenday_head’ not found or invalid function name
- Don’t delete a page if it holds users
- Passing values from a widget to a function within a plugin
- Which action does wp_update_user triggers?
- How can I get my Script to work on the Login page?
- Trigger a custom function when option are saved in admin area
- Execute a ultimate member action when user role is updated
- Add other social networks to TwentyNineteen_SVG_Icons class in child theme?
- How to use wp_trash_post (or wp_delete_post) for deleting a (or all) post(s) from custom post type?
- Replace a menu with widget or a custom template file programmatically
- Footer disappears when using the_content ( )
- Get User Login Data (date, time… )
- jQuery does not work
- Override the WordPress core function wp_referer_field
- How to return hook data when multiple parameters are present?
- Hook into a function without a hook?
- What is the text that appears beside the page titles in the list of pages in the WP admin?
- How to edit the Tags within the image file URLs?
- Control the srcset much more (not all sizes in it each time)
- How to add_filter html template to middle of content
- Filter yoast canonical add_action priority [closed]
- How do I hook into the container of wp_nav_menu?
- Remove links from the_content when using filters wp_trim_excerpt
- Is there a way to prevent a function/method from being called outside a specific hook?
- Auto log in hook is requiring a page refresh
- Possible to hook into Media Library preview File column and use a custom image?
- Function not working inside of a function in functions.php
- Adding code before post title with the_title produces weird results
- Add back in child theme what the parent theme removed with remove_action
- Writing a function to detect an event
- This code works, but the way I integrated it is breaking the media uploader. How can I integrate it properly?
- WordPress wraps span tags into p tags
- Changing where my author box is printed
- Add Adsense code between job listings – wp job manager plugin
- Replace admin header logo with an image
- Why I can’t load my JavaScripts using an hook inside my functions.php file?
- is_home() not working in functions.php file
- How to place a div inside a function that creates a div
- Filter for replacing the WP_query object for a given category
- WordPress comment processing . Default unapproved comments detection before posting
- Does hook have an effect on increasing the page load?
- Save_post – Warning: Cannot modify header information
- What is the earliest Hook a Script can use?
- Populate acf-field, depending on block name
- How to use WP conditional tag in a functions.php with OCEANWP Theme?
- custom error message for empty username and password using authenticate filter not working
- How Do I Unhook This Parent Theme Function?
- Get post_author email for Zapier Integration
- Calling hooks in functions
- How to add custom column into custom post, when field is select
- How can I stop the hook from breaking the login/logout function?
- WordPress hooks to call a function inside a construct
- WordPress undefined function error on using add_action() in functions.php
- How to echo the translated custom field?
- Function the_content
- save_post hook – headers already sent?
- Add custom fields after post/page title
- Force resize for all video content
- Unhook the comment form in Buddypress
- Why wp_ajax hooks doesn’t work?
- How can I append and prepend something to all post hyperlinks without using ::before or ::after? PHP hook solution?
- Why functions metaboxes is causing White Screen in Admin [closed]
- image_size with respect to aspect ratios
- delete_term is not working properly with add_action()
- Create section wit form
- Copy and Modified WooCommerce function is_coupon_valid [closed]