skip to Main Content

How can I display a div box with ID only for the corresponding author of the wordpress page?

for example

when testuser is logged in he should see a div box with id="author" inside his post (post/test2/).

but

if another user is logged in he should not see the div box with id="author" within the post (post/test2/).

Is there a possibility? Unfortunately I’m a beginner and don’t know how best to approach the problem.

2

Answers


  1. Chosen as BEST ANSWER

    i made it for the admin but i want the id to be visible only to the author of the post.

    example:

    if the author is logged in he should see the content with the id=author.

    but

    if another user is logged in he should not see the content with the id.

    /* hide role-specific div */
    #author {
      display: none;
    }
    
    body.logged-in.admin-bar #author {
      /* Admin is logged in*/
      display: flex;
    }


  2. Although, your question is not so clear about your requirements. What I understood is you are looking for an Author box on the post, in the standard WordPress theme hierarchy it is called Single, and the file is single.php

    You can try by adding div conditionally checking for the post author.

    if( is_user_logged_in() && is_author(get_current_user_id()) ) {
    
        // add your div code here for the post author.
    
    }
    

    If that is not the solution you are looking for, please share some code samples you are working on with a better explanation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search