Just make sure auth_redirect()
is executed for the user on the desired pages (before any content is printed).
There are many ways to do this. You can add something like this to functions.php
$pages_auth_check = [ 25, 40, 55 ]; // IDs of the pages to check.
$current_page = get_the_ID();
if ( in_array( $current_page, $pages_auth_check ) ) {
auth_redirect();
}
So the auth_redirect()
will be executed only for the pages with the specified IDs.
Related Posts:
- Change the footer text on the login page
- Login/logout in header
- getting logged in user info (wp-load.php) from parent directory
- Log in / Log Out Custom Button
- How to display login form anywhere, when user isn’t logged in, without redirecting?
- Can’t log in to WordPress wp-admin after adding code to functions.php
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Restrict wordpress access to logged users only
- Menu not updating for logged in users after redirect
- Refresh page after login with litespeed cache
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- is_user_logged_in() not working in homepage
- start_lvl Ignored in Custom walker_nav_menu
- Enforcing password complexity
- Customize default settings on new sites on multisite
- Check if a menu is empty?
- Dynamically change feature image in customiser
- Creating wordpress user registration form
- Get the title before comma
- category not display in word press grammatically
- Setting up the child theme so as to enable right-to-left WordPress?
- Design view breaking on Pages
- Getting a fatal error while updating
- Hooking new functions to actions + passing parameters
- Display 4 chronological posts starting with a random post
- my function doesn’t return my post from today
- How to break down importing of feeds
- WordPress shows registration link for non logged users
- get_the_terms – only top level
- Have CSS Class Added with `is_page()` WP function
- Slide in Panel WordPress Post
- Use wp_get_recent_posts with search term
- Calculations in functions.php [closed]
- comments_number display outside specified span
- Choose To Display Post Views With An Options Panel
- Prevent Data Resubmission On Page refresh
- Get_avatar filter?
- WordPress custom login form using Ajax
- Passing the custom field values in the wp_get_current_user array function
- Why is my cookie not unsetting upon logout? [closed]
- Get value from shortcode to do something
- PHP 8, AJAX mail form to function.php doesn’t work
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- How to create a php variable using WordPress the_title() function
- Can’t find infinite loop cause
- how to make custom ajax handler?
- How to disable controls in theme customizer?
- register_taxonomy() take much queries
- is there a benefit in using a constant over get_stylesheet_directory_uri?
- WooCommerce Tabs [closed]
- ::before on open/close function [closed]
- REQUIRED: get_bloginfo(‘template_url’) was found in the file search.php. Use get_template_directory_uri() instead
- How to check if a PHP string is different than meta field?
- Displaying posts based on category
- Countdown to date function?
- Creating a mobile site by adding a new class to the body tag from functions.php
- calling a custom field value inside functions.php
- Issue with fetching mysql data and displaying results via shortcode in webpage
- Noindex Posts From Certain Authors In WordPress
- Show all tags within a category?
- WordPress check if current taxonomy has child
- This function is deprecated; use mysql_real_escape_string() instead
- get_theme_mod outputs number when using WP_Customize_Cropped_Image_Control
- Custom Taxonomy Select Menu: Setting default option value?
- How can I alter this code to accept a slug as well as an ID?
- Enqueueing a code block from an options framework
- Show login greeting above sub-menu links?
- Conditional On custom field plugin metabox
- Adding a ‘style=’ bit to image_send_to_editor output
- Post Views Code Hacks
- Closing WP_LINK_PAGES DIV ID w/After Argmuent
- Exclude function from running on a certain page
- Auto create Nextgen Gallery on post creation [closed]
- Hide media for non logged in users
- Adding an “Upgrade Subscription” button to an Elementor page
- Jetengine Forms – Media upload path
- Using ACF Relationship field to set post type to draft or published status
- Custom function that re-writes page title breaks when the Yoast plugin is activated
- is_front_page is not working in my functions.php
- Is it possible to update the dataset using update_post_meta
- update_user_meta as multiple value but with same meta key
- Hide payment method based on user role AND minimum cart value
- Update $wpdb query with AJAX
- How to bind each “the_content” elements to a custom variables
- Permalink changes after several minutes after saving post
- How do I get the value of a current user’s custom field?
- Adding extra data to shortcode attributes and pass it to JS with wp_localize_script
- Allow Comments by Default for Multiple Post Types
- Cleaner ‘for each’ loop for registering scripts in functions.php
- wp-login.php?redirect_to=https problem
- How to get User Avatar Image with link to Author and User name in Html Title tag?
- WP HTTP API call response
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- How to get all users by user_login as a json_encode array?
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Postmeta not saving
- Fix My Custom Function: Remove Automatic
- Hide the content before the more tag in the “single page”
- WP Debug enabled Undefined index error in a widget
- how to loop through blog posts in php