I want to show a sidebar only to the author of a post.
How do I do that?
Thanks
Medeea Selected answer as best
I want to show a sidebar only to the author of a post.
How do I do that?
Thanks
To show your sidebar only to the author of the post, you need to first locate the get_sidebar()
code in your theme files. Usually this code can be found in the root of your theme, in the file single.php
Then replace the code get_sidebar()
with this one
function show_sidebar_only_to_author(){ global $post; $page_id = get_queried_object_id(); $user_id = get_current_user_id(); $author_id = get_post_field( 'post_author', $page_id ); if ( $user_id == $author_id ) { get_sidebar(); } } add_action( 'get_footer', 'show_sidebar_only_to_author' );
Hope this helps.
Login bellow or Register