WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Hide author info when admin post (10 posts)

  1. petej830
    Member
    Posted 2 years ago #

    I have a blog were I post the headlines in the news from other sites(like a news feed). Since I did not write the article I don't want my name to show up as the author. I do however have contributes that post original articles and I wan't there name to show in there post. I already know how to hide author info completely but I want it to show when contributors write. Is there anyway to hide author info just when certain member post story's?

  2. s_ha_dum
    Member
    Posted 2 years ago #

    Do you need to remove more than just the author? For example, if you have this "author | Posted on xxxx/xx/xx" do you need to remove all of it or just the 'author'? If the later you can probably do it with a filter, if the former you most likely need to edit your theme.

  3. petej830
    Member
    Posted 2 years ago #

    I just need the "author" not to show. I looked everywhere for a plugin that would do it but I've found nothing. I was hoping for a plugin that would show when I'm adding a new post and I can check it if I want to hide the author. They do have "Post Anonymous" plugin but all that does is say the author is "anonymous". If I click on "anonymous" it takes you to the users profile that is trying to stay anonymous, so that didn't work to good. I know this is a tough one because not to many people would need something like this. But if anybody has any ideas please let me know. I was thinking some type of code that said "if posted by this user then hide author" That's what I need. I've been battling this issue for a couple of weeks now.

  4. s_ha_dum
    Member
    Posted 2 years ago #

    It isn't hard to filter particular users, actually. In your theme's functions.php :

    function hide_admin_author($author) {
      if ('admin' !== $author) return $author;
    }
    add_filter('the_author','hide_admin_author');

    If your admin author shows up as 'admin', that will hide it. You can edit the conditional or cook up more complicated logic if you need to.

    This isn't the plugin with a check box you mentioned but maybe it will help.

  5. petej830
    Member
    Posted 2 years ago #

    Awesome! Thank you s_ha-dum that actually! I figured it would be a simple code you could put in. Now if I want to do if for multiple members not just the admin do I do the same code just change where it says "admin" to whatever the other members names are?

    function hide_editor_author($author) {
    if ('User Name' !== $author) return $author;
    }
    add_filter('the_author','hide_editor_author');

    do the same code twice? One other think that's not a big deal is now it has "By On July 22, 2012 Add Comment" is there a way to take the "By" out?

  6. s_ha_dum
    Member
    Posted 2 years ago #

    You can make a more complicated conditional.

    function hide_admin_author($author) {
      if (
           ('admin' !== $author) &&
           ('user1' !== $author) &&
           ('user2' !== $author)
      ) return $author;
    }
    add_filter('the_author','hide_admin_author');

    That code is overly formatted but more readable with the extra parenthesis. It means "if 'admin' is not the author name and 'user1' is not the author name and 'user2' is not the author name, then return the author name." If all of the conditions are true it will print the author. If even one of them is false the whole thing is false.

  7. petej830
    Member
    Posted 2 years ago #

    Awesome that worked great! You've been a big help. Thank you

  8. johnkwhite
    Member
    Posted 1 year ago #

    I'm trying to solve a similar issue. Hiding the author info if a certain category is selected for the post.

  9. kgionet
    Member
    Posted 1 year ago #

    I have tried the solution s_ha_dum suggested, but the "By" just before the author's name is still visible. Where can I edit that out?

    Thanks.

  10. thesaraheffect
    Member
    Posted 1 year ago #

    I have the same issue johnkwhite has. Is there a way to hide specific metadata from a specific category??

Topic Closed

This topic has been closed to new replies.

About this Topic