• Hello!
    Please, please help!
    I need to display the post author’s page. By default, it has the address: example.com/author/username .
    But, I want to make it so that I can insert a link in the header of the Site, by clicking on which, the registered author could go to his page, where only his posts are visible. But if I insert this link ( example.com/author/ ), then the user (author) goes to this page, but his username is not pulled up, it turns out like this – example.com/author/ , but it needs to be like this – example.com/author/username .
    Please help me with this, how to set up a link so that by clicking on it, a registered user (the author of the post) can go exactly to his page of the post, where he is the author. Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • simple little plugin:

    <?php
    /*
    Plugin Name: Author Button
    Description: Creates a link to the current logged in author's page
    Version: 1.0
    */
    
    function add_author_button_tug1sf8(){
    	if (is_user_logged_in()){
    		$userData = wp_get_current_user();
    		$authorLink = '';
    		$authorNiceName = $userData->display_name;
    		$authorURL = get_author_posts_url($userData->ID);
    		$authorLink .= '<a href="'.$authorURL.'">'.$authorNiceName.'</a>';
    		return $authorLink;
    	}
    }
    add_shortcode('authorButton', 'add_author_button_tug1sf8');
    ?>

    that will produce the link like you want.

    Thread Starter vens007

    (@vens007)

    dear man, thank you! do not take it for impudence, but where to insert it?) I will be very grateful!

    @vens007

    It’s a plugin so you can add it that way and a short code of [authorButton] will display it.

    Thread Starter vens007

    (@vens007)

    Please, could you specify where to register it? It’s clear with the shortcode, but here’s what the plugin means. In my understanding, a plugin is an elementor and so on. I beg you, tell me step by step, if possible. I understand that I’m tired of stupid questions, but I can’t figure it out. I hope very much for your help..

    Thread Starter vens007

    (@vens007)

    As I understand it, you need to go to the plugins in the console, then edit the plugin and paste this text:

    <?php
    /*
    Plugin Name: Author Button
    Description: Creates a link to the current logged in author's page
    Version: 1.0
    */
    
    function add_author_button_tug1sf8(){
    	if (is_user_logged_in()){
    		$userData = wp_get_current_user();
    		$authorLink = '';
    		$authorNiceName = $userData->display_name;
    		$authorURL = get_author_posts_url($userData->ID);
    		$authorLink .= '<a href="'.$authorURL.'">'.$authorNiceName.'</a>';
    		return $authorLink;
    	}
    }
    add_shortcode('authorButton', 'add_author_button_tug1sf8');
    ?>

    save that code locally. add it to a ZIP file. go to plugins -> add new -> upload plugin and select the zip file. Then activate it. That’s how you install a plugin.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘post author page’ is closed to new replies.