php - how to get avatar on front end wordpress

640

Hello users of stack over flow, I have a little Question,

I am trying to get avatar in upper end of my website, if user is logged in I want to show

avatar and name and link to profile,

if user is not logged in I want to show login and register buttons

I know little bit of php only , I will have to use if else statement but how to call wordpress logged in user function ,

thanks

(if you provide me with a sample code that will help a lot)

I tried something like this

But I got erros , Please can someone tell me what I am doing wrong

295

Answer

Solution:

For example;

 <?php
    if ( is_user_logged_in() ) {
        if (function_exists('get_avatar')) { 
          echo get_avatar( get_the_author_meta('user_email'), 68 );
          the_author_meta('display_name');
        } 
   } else {
       echo '<a href="'.wp_login_url( get_permalink() ).'" title="Login">Login</a>
   }
  ?>

Your code must be like this,

People are also looking for solutions to the problem: Run powershell in php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.