# Log In/Out Link at the End of the Navigation Block

> Adds a Log in / Log out link as the last item of your block theme's header navigation automatically, using block hooks.

- Type: PHP
- Runs: Run everywhere
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: block-hooks, navigation, login
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/block-hooks-loginout-in-navigation/

## Code

```php
add_filter( 'hooked_block_types', function ( $hooked, $position, $anchor, $context ) {
    if ( 'last_child' !== $position || 'core/navigation' !== $anchor ) {
        return $hooked;
    }

    if ( $context instanceof WP_Block_Template && 'header' !== $context->area ) {
        return $hooked;
    }

    $hooked[] = 'core/loginout';

    return $hooked;
}, 10, 4 );
```

## Notes

Applies to Navigation blocks inside the header template part. Remove it in the Site Editor if you change your mind. Needs WordPress 6.5+.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Log In/Out Link at the End of the Navigation Block" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
