0

I am running a news website, most of the posts are from an Editor Account. I want to hide the author-box displaying at the bottom of the posts, only for this user. Only author box of Editor should be hidden from public.
Is there any way to hide the author box of a particular user from public, with a funtion?

Author box element is in loop-single.php file. wrapped in the footer of the post,

<?php echo $td_mod_single->get_social_sharing_bottom();?>
    <?php echo $td_mod_single->get_next_prev_posts();?>
    <?php echo $td_mod_single->get_author_box();?>
    <?php echo $td_mod_single->get_item_scope_meta();?>
  • Show us what you've tried till now. And share the code where you wanna hide the author box. – CodeMascot Dec 20 '16 at 11:07
  • I am not good at coding. So far i have used some functions but nothing worked. – Davood Dec 20 '16 at 11:09
  • function remove_my_post_metabox() { if (get_the_author_meta('ID') == 2) { echo '<style type="text/css"> .author-box-wrap { display: none; } </style>'; } } add_action( 'add_meta_boxes', 'remove_my_post_metabox' ); – Davood Dec 20 '16 at 11:09
  • also use this 'function remove_my_post_metabox() { global $post; // If the post author ID is 1, then remove the meta box // You would need to find the ID of the author, then put it in place of the 1 if ( $post->post_author == 2) { remove_meta_box( 'author_box','post','normal' ); // Author Metabox } } add_action( 'add_meta_boxes', 'remove_my_post_metabox' );' – Davood Dec 20 '16 at 11:15
1

If you know the data of the author, you can wrap that box with an if and the function get_the_author

if( get_the_author() == "name_of_the_author" ){
// Don't do it
}else{
// Print box
}

EDIT with the final answer updated:

<?php echo $td_mod_single->get_social_sharing_bottom();?>
<?php echo $td_mod_single->get_next_prev_posts();?>
<?php
 $user = get_user_by("login", "pknn"); // user object
 // get_the_author() needs the display name, not the login
 if( get_the_author() != $user->data->display_name ){
  echo $td_mod_single->get_author_box();
 }
?>
<?php echo $td_mod_single->get_item_scope_meta();?>
  • The user-id is 2, username is 'pknn'. How can i use it in my functions.php? – Davood Dec 20 '16 at 11:12
  • Show us the template of the single-post.php or the php file that is printing that box so we can understand where does it comes from. But whatever is it called, just put that code around it and it should work. – dgarceran Dec 20 '16 at 11:18
  • It is in loop-single.php file inside the footer of the post. I am new here, so don't know how to paste the code properly in a readable form. Sorry. Can you please tell me how can i paste it properly – Davood Dec 20 '16 at 11:25
  • Here is a sample post link [pristinekashmir.com/news/kashmir/… – Davood Dec 20 '16 at 11:27
  • Edit your original post and check out the information that is displayed in the text box. If you paste the code, select it and the click on the brackets {} icon, and it should be pasted correctly. – dgarceran Dec 20 '16 at 11:28
0

It's unclear for me if you want to hide the author box for users with 'editor' role of for the user 'Editor'.

Here's the code for detecting if an user has the editor role and that shows the author box for all other roles:

// Add this in you single post template
// See https://developer.wordpress.org/themes/basics/template-hierarchy/

// First we get the author role:
global $authordata; // The author object for the current post. See https://codex.wordpress.org/Global_Variables
$author_roles = $authordata->roles; // Get all author roles. See https://codex.wordpress.org/Class_Reference/WP_User
$author_role = array_shift( $author_roles ); // Get the user role

// Now we check if the author is an editor
if ( $author_role != 'editor' ) {
    // Show the author box
}

If you rather want to hide the author box for a specific 'Editor' user, use this instead:

// Add this in you single post template
// See https://developer.wordpress.org/themes/basics/template-hierarchy/

// First we get the author username:
global $authordata; // The author object for the current post. See https://codex.wordpress.org/Global_Variables
$username = $authordata->user_login; // Get the author username. See https://codex.wordpress.org/Class_Reference/WP_User

// Now we check if the author username is 'Editor'
if ( $username != 'Editor' ) {
   // Show the author box
}

Let me know if you find this useful.

  • I have a user with 'editor' role namely Editor. This account is used to update news posts. Now i don't want to show this user's author box to anyone, hidden from public, hidden from everyone. Thanks for helping – Davood Dec 20 '16 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.