The key plugin was https://www.ads-software.com/plugins/http-headers/
in my initial experiments.
All I had then did was simply enable all the options. Default values where left blank even when enabled. This seemed to help.
However, on experimenting with themes (even those published by WordPress) the effects observed were inconsistent over a number of mobile devices.
Overall, I would say that it struck me that the latest version of WordPress does not support opening of password-protected page on mobiles.
The only viable solution that I have had modest success was in exploring user role with restricted access to posts and pages (recent WordPress convention, as I understand, treats posts and pages the same).
To achieve my goal, I relied on the following links:
Restricting pages to logged in users only
Custom user roles
Disable the admin bar for specific user
Fixing redirect issues
I added the following code at the end of the function.php file of the active theme:
/*Customization for user role based page restriction */
/*Customized on 09-01-2019 */
add_role(
'custom_subscriber',
__( 'Custom Subscriber' ),
array(
'read' => true, // true allows this capability
'edit_posts' => false,
'delete_posts' => false,
'publish_posts' => false,
'uploadfile' => false,
)
);
add_action( 'template_redirect', 'protect_testavcheck_page' );
function protect_testavcheck_page() {
global $post;
if( $post->ID == 5 || $post->ID == 11 ){
if( ! is_user_logged_in() ){
wp_redirect( home_url() . '/login' );
}
}
}
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
Before adding the above code section in the function.php file, I had created a page and a post with the slugs testavcheckpage and testavcheckpost, respectively. The respective post IDs were 5 and 11 which I duly noted and placed in the code section as produced above.
To ensure that the administrator bar would not show up for a guest role, or for that matter any other role except for administrators, of course, I also included the last few lines as shown in the code above.
At this stage, I discovered that these were not enough. While there were no problems in conducting the exercise of restricting such a user to a particular post on a PC, on mobile devices, however, the error message that kept on repeating was of too many redirects.
It took me a while to figure out that the wp-login.php was somehow not being recognized on mobile devices. The reason as yet remains unknown to me. However, what I intended to do, and which I did was to install the following plugin:
User Registration Form
What this did was allow me to create separate page [Logging in page or My Account Page] for logging in. All I then needed to do was to change this:
wp_redirect( home_url() . ‘/login’ );
to this:
wp_redirect( home_url() . ‘/my-account’ );
in the file function.php.
Interested forum members can test the links using
as username as well as for the password.