You can install and activate a WordPress plugin called Inactive Logout.
Here are the steps to enable the auto-logout feature in WordPress.
1. Log in to WordPress Admin.
2. Select the Plugins menu and click the Add New submenu to install a new plugin.
3. You will be redirected to the Add Plugins page. Use the search feature to find the Inactive Logout plugin. Click the Install Now button to install it.
4. Once the plugin is installed, click the Activate button to activate the plugin.
5. Select the Settings menu and click the Inactive Logout submenu to configure.
6. The Inactive User Logout Settings page will appear. You can specify the automatic logout time. For example, we set a time of 5 minutes, so that the WordPress Admin page will automatically log out, if there is no activity running during that time. Underneath, write a message about the automatic logout.
7. Scroll down and click the Save Changes button to save the settings.
8. Try to stay inactive for the time you've set. Eventually, the Session Timeout pop-up screen will appear like this and WordPress will automatically log you out.
9. Next, you'll be prompted to re-login to WordPress. Congratulations, the WordPress auto-logout feature is now active.