The discussion revolves around changing the author link in WordPress to link to the author’s profile in Discourse. davidkingham initially shared a code snippet that attempts to achieve this goal, but was unable to retrieve the Discourse username from WordPress.
simon suggested using get_user_meta( $user_id, 'discourse_username', true ); to retrieve the Discourse username, where $user_id is the user’s WordPress user ID. However, davidkingham encountered issues implementing this solution.
simon identified the problem and provided a revised code snippet that passes the author’s ID as a parameter to the function and checks if the Discourse username has been set. If it has, the function returns the link to the author’s Discourse profile; otherwise, it returns the default author link.
The revised solution was successfully implemented, and davidkingham expressed gratitude to simon for their assistance.
$user_id needs to be set to the user’s WordPress user ID. Since it’s possible that not all authors will have set their Discourse username, you should probably check that the value returned isn’t empty before creating the link.
Yes, $user_id isn’t available inside of your function. You need to pass the author’s id to the function as a parameter. Try this code. It also checks if the Discourse username has been set. If it’s not set, the default author link will be returned.