Showing sidebar only to author of post
-
I am trying to show the sidebar only if the user viewing the post is the author of that post. So anyone else viewing the post, if they are not the author, then they cannot see the sidebar.
So if “John” wrote ‘Post A’ but “John” did not write ‘Post B’, then “John” can see the sidebar when he is viewing Post A, but he can not see it when viewing ‘Post B’.
I have tried many variations of this but nothing seems to do the trick. Either the sidebar disappears for everyone, including the author, or it is visible to everyone.
Also, I am using a custom post type that I made called ‘campaign’, not sure if that is why this isn’t working.
$author_id = get_post_field ('post_author', $post_id); $current_user = wp_get_current_user(); function showSidebarWhenNeeded() { if ( $current_user->ID !== $author_id ) { echo '<style>.widget-area{ display: none !important;}</style>'; } } showSidebarWhenNeeded();
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Showing sidebar only to author of post’ is closed to new replies.