admin_init
runs on admin pages, not the front end. The equivalent front end action, init
, is too early to check is_page
. A safe action for redirection is template_redirect
:
function xyz() {
if( is_page( 172 )
&& ! current_user_can('update_core') ) {
wp_redirect( home_url() );
exit;
}
}
add_action( 'template_redirect', 'xyz' );
Related Posts:
- How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
- Restrict dashboard access for specific user roles to specific actions
- Redirect admin 403 “Cheatin uh?” admin pages
- Redirect non-admin after login, and in url – /admin
- How do I remove dashboard access from specific user roles?
- Can an admin check passwords of registered users?
- Prevent author from changing their posts if admin has modified
- How to remove administrator role in settings -> general -> New User Default Role?
- Redirect Admin User in Dashboard
- Create un-removeable user
- Custom CSS In Admin Only For Certain Roles
- Remove ability to access certain admin menus
- Remove admin AND editor from the “change role to” menu in user listing
- Customize the upload screen
- Blocking Administrative Access to Authors and Subcribers?
- Customize Admin Users Screen based on Role
- Make certain pages uneditable by editors?
- How to display only logged in user’s post comments in comments area
- how to redirect to url.com/wp-admin if url.com/admin is typed in?
- Change the Default Pages Menu View in wp-admin
- How can I restore admin capabilities?
- Protect custom php file with login
- Admin page redirect to another admin page
- What determines whether admin toolbar is shown to a logged-in user?
- front end editing using iFrames, best approach?
- How do you set up a WordPress blog with multiple authors to allow something like StackExchange’s “community wiki” feature?
- Displaying different in-page content to cliente/admin
- WordPress Admin Login Redirect Problem
- How to hide a specific part of dashboard for non-admin roles?
- WordPress administrator area access disabled temporarily due to widespread brute force attacks
- WordPress Remove Submenus
- Redirect in an Admin page
- Redirect from the dashboard to edit.php if wp_is_mobile() is true
- Create a WordPress administrator without access to back-end
- Only Admin can Edit, Delete or Update
- add_cap for editor but no admin role
- Shared account / dual blogging in WordPress
- Bind custom role to admin page
- Access for adding subpages but not for pages
- remove menus for a specific role?
- Can’t login to my admin area
- Allow admins to login as other users
- current_user_can(‘administrator’) not working in custom login
- Show global Message in User Profiles with admin only Input field in WordPress Backend
- How to make sure your admin doesn’t hi-jack you site?
- Redirect public site to another one but allow administrators to access the old site
- Given multiple admin accounts, how can I make it so that only admin with X username can edit posts
- How should I setup the “Users” area to hand over to a client?
- solution to prevent specific admins from altering site contents
- Admin user roles/permissions
- Posts in sidebar only by admin
- How To Remove Import/Export Option From Tools?
- Doesn’t call user information to include “wp-load.php” in an external php file
- Hide top admin panel for non admin and non editors
- How can I create multiple different admin roles with their own capabilities
- ‘Conflict’ with action deleted_post and is_admin()
- Signed-in as admin on just part of the site
- Different role for free and pro users in wordpress without using bbpress
- Capability to read/edit page in wp-admin only for administrators
- WP Logs me out after updating anything on dashboard
- You do not have permission to access this document on form submit
- Different customer login form than administrator login form?
- Administrator user cannot access dashboard after localwp import
- What are the standard admin CSS id/class tags?
- Admin Ajax is returning 0
- Add custom column to Users admin panel
- Allow member to have access to custom post type only. Permission to only edit their own posts
- wp_verify_nonce vs check_admin_referer
- Add a Separator to the Admin Menu?
- How to determine whether we are in add New page/post/CPT or in edit page/post/CPT in wordpress admin?
- how to know if admin is in edit page or post [duplicate]
- Modal window from within WordPress admin
- Where in WP can I check history or log of updates of plugins etc?
- Admin Page Redirect
- Adding a custom admin page
- How does admin-ajax.php work?
- How to check if user is in back end?
- Remove update nags for non-admins [duplicate]
- Give Editor Access To Sidebar
- How to remove entire admin menu?
- How can I speed up my WP admin section?
- How to pass parameters to admin_notices?
- Admin: very slow edit page caused by core meta query
- if admin is logged in
- Search posts by ID in admin
- How to Change the Default Home Page for the WordPress Dashboard?
- Setting admin edit panels & metaboxes positions and visibility for ALL users and admins
- Find out which moderator approved comment?
- The website cannot display the page
- How To Remove WordPress Version From The Admin Footer
- Sort pages in loop by admin’s page attributes order field?
- Edit “thank you for creating with WordPress” in version 3.3.1
- Hide other users’ posts in admin panel
- Check IF is a “single product page” and Check the “role” for a Redirect
- Set Default Admin Colour For All Users
- Editor Styles and Typekit
- WordPress admin stylesheet
- This CSS Stuffing Works, But Is This A Good Practice?
- Is it possible to create a WordPress tour? V3.3.1
- Securing Admin Accounts – Username Discovery