I wanted to know if there were any ways to easily hide a selected user's user page. I've yet to find any code that does so. I've only found code to remove all user pages.
Thanks
I wanted to know if there were any ways to easily hide a selected user's user page. I've yet to find any code that does so. I've only found code to remove all user pages.
Thanks
Share Improve this question asked Mar 9, 2017 at 5:37 bakingsodabakingsoda 755 bronze badges3 Answers
Reset to default 1I'm assuming you want to hide the author page on the site itself (and not in wp-admin
).
To do that, just create a new template file called author-{$id}.php
, where {$id}
is replaced by the ID of the author you want to hide. So if the author ID is 6
, the template file should be called author-6.php
.
Inside the new file, put this in:
<?php
header( "HTTP/1.1 301 Moved Permanently" );
wp_redirect( get_home_url() );
exit;
?>
Now when you try to load the author's page, it will just redirect to the site visitor to your home page.
(Source)
If you want to hide the user in user list page. The following working for you.
//yousiteurl/wp-admin/users.php
Here is the code which hides specific user. It is tested and working fine.
Add this in functions.php in your theme.
functions.php
//change user-14 to your user id.
<?php
add_action('admin_head' , 'ft_hide_administrator_user');
function ft_hide_administrator_user(){
global $pagenow;
if ( 'users.php' == $pagenow ){
wp_enqueue_script('jquery');
}
?>
<style>
#user-14{display:none;}
</style>
<script type='text/javascript' >
jQuery(document).ready(function(){
//jQuery('#user-14').remove(); // to remove users.php list page html
jQuery('#user-14').hide(); // to hide users.php list page html
var total_count = jQuery(".users-php .subsubsub li.all .count").text();
total_count = total_count.substring(1, total_count.length - 1) - 1;
jQuery('.users-php .subsubsub li.all .count').text('('+total_count+')');
var total_count = jQuery(".users-php .subsubsub li.administrator .count").text();
total_count = total_count.substring(1, total_count.length - 1) - 1;
jQuery('.users-php .subsubsub li.administrator .count').text('('+total_count+')');
});
</script>
<?php
}
I think we can use pre_user_query
filter and modify or adjust the where
query.
Something like the following code:
add_action( 'pre_user_query', function( $uqi ) {
global $wpdb;
$uqi->query_where .= ' AND id != 1';
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745060324a4608927.html
评论列表(0条)