show_user_profile
is the wrong hook to use. You should redirect before anything gets sent to the browser (eg. before headers are sent).
Fortunately there are actions that happen much earlier: load-{$pagename}
is the one you want. So you can hook into load-index.php
and load-profile.php
to throw people back to the front end.
<?php
add_action( 'load-profile.php', 'wpse35742_maybe_redirect' );
add_action( 'load-index.php', 'wpse35742_maybe_redirect' );
function wpse35742_maybe_redirect()
{
if( current_user_can( 'manage_options' ) ) return;
wp_redirect( home_url( '/profile' ), 302 );
exit();
}
All that said, you would be better off adding a new role that has even more limited capabilities than the typical subscribers: don’t let them view the dashboard or their profiles (the read
capability).
Related Posts:
- How to manually activate user in dashboard only by admin
- How do I create a new WP admin color scheme?
- Change labels on ‘Nickname’ and ‘Biographical Info’ in user-edit.php
- I changed “Howdy” in the admin bar in the dashboard, but when I’m viewing the site it still says Howdy!
- Create dropdown of users in admin dashboard
- Display WooCommerce subscriptions for user [closed]
- Adding widget to dashboard with wp_dashboard_setup not working
- Dashboard widget custom positioning?
- WordPress function only executes once
- Sortable column (by numbers) in admin users
- How to remove some item from WordPress Dashboard for user Author
- Add Link to Users List (Backend) to open each users front-end profile
- How to display my comment count in the wordpress admin bar?
- Remove theme, change theme button and WP version on “Right Now” admin dashboard?
- Code in functions.php appearing on front-end and dashboard [closed]
- What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
- Is it possible to rename a post format?
- Is there a hook or function I can use to display all theme files being used on a current page?
- How to paginate the get_users function?
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- How can I remove the title “leave a reply” in the comment box in twentyeleven?
- Child theme – overriding add_image_size by a child theme [duplicate]
- Check if has any sidebar active on current page
- Compare post levels and user levels wishlist member
- Change ul class=”children” for wp_list_pages?
- Target a certain page within wordpress backend (admin) i.e. Pages > About
- Set default options for inserting media
- Remove tag on my RSS Feed
- Automated mark posts as featured every day
- Session is not starting
- Child Theme Not Overriding Parent Theme
- Trouble using antispambot()
- Polylang: pll_e() & pll__() on functions.php, doesn’t work
- Disable shortlinks like ?p=1234 to prevent scraping
- Post Pagination Showing Same Posts Every Page
- WP_Remote_Get Not working
- Debugging with functions.php
- Getting first Image from post
- Inserting a functions output after the content
- Combine two different filter callback functions
- Don’t delete a page if it holds users
- Ordering posts by publish date not working?
- Change label for registration Fields
- Warning: : DOMDocument::loadHTML(): Empty string supplied as input in functions.php when adding classes to post images
- Remove stylesheets from Campaign Monitor plugin
- How to install Segment on WordPress without a plugin
- How to search using ajax for exact phrase or words in an input field?
- I can’t enqueue my scripts – They literally aren’t being added to my site
- Using wp_redirect and .htaccess to re-route searches (and pass along the remaining GET vars)
- Multisite 404 on pages – rewrite error breaks database
- Need help “sanitizing” a custom function that pulls category slug into body class
- Make wp_link_pages() suitable for Twitter Bootstrap markup
- How to get data from an array using get_user_meta()
- Space Not Being Generated in HTML Output?
- Prevent custom field from being updated after first publish
- How to edit classes in body tag?
- Do not show on homepage functions.php code needed
- Add a field into a shortcode of an extension
- $_Get and &_REQUEST Index Undefined on Functions.php
- Load scripts for do_shortcode( ‘ [ my_shortcode ] ‘ )
- get_terms and meta_value results blank
- get_template_directory_uri() links to child theme not parent
- Functions Filter Question [closed]
- Dequeue scripts in IE7 only using functions.php
- Why I can’t load my JavaScripts using an hook inside my functions.php file?
- Featured Image keeps cropping
- Function Suddenly Stopped Working
- Prevent creating multiple image resizes in twentytwelve template
- Shortcode of a function
- Get URLs for AJAX Filter Checkboxes WordPress
- Using One Function To Create Two Different Shortcodes
- Change Page Title
- How to Not Show posts on Category page?
- Put images in the media from url functions
- Paragraph spaces in email template function
- Is it possible to load recaptcha script only in url with fragment identifier (#)?
- page shows short code not output
- Scheduled post delete – can’t pass the cron arguments
- Prevent function from triggering on current page
- Assign IDs to headings in ACF using functions.php
- How would I correctly implement a new if statement in a child functions file?
- Multiple Notifications SetInterval
- Child Theme not loading multiple stylesheets
- How To Show Shortcodes In WordPress Custom Fields?
- Class::$template_dir_path=get_template_directory();
- Post date on Custom field
- Fatal error: Call to undefined function add_action() – an untouched problem
- Author info does not show up when author has no posts
- How to wp_enqueue_script with html?
- Modify sub_menu function to show pages below a specifically set page
- Add custom class to all URLs on entire site
- Is it possible to change parameters of Parent theme function in the Child theme?
- Error function main() is a non-object to construct my Ajax.php
- Unregistering custom tinymce plugin?
- Combining wp_current_user() and a variable
- Init hook for header send
- java script error Uncaught SyntaxError: Unexpected token ILLEGAL
- site_url is not honoring scheme
- new to javascript – using in instead of functions.php, not loading correctly
- Remove Disqus JavaScript from homepage