Technology WordPress Tips & Tricks

Create Author Widget in WordPress using PHP Code Widget

Showing author details in a widget adds a personal, trustworthy touch to your content. Here is how to create an author widget in WordPress using the PHP Code Widget, so your writers get the spotlight they deserve.

Namrata Namrata 3 min read
Newly Launched Frontend Learndash Dashboard and its feature

Author WidgetWe all want to personalize our blogs or websites. May it be in terms of the content displayed, or the features presented. In my attempt to add a custom feature in my blog, I went about exploring how to add author information in a sidebar widget.

 

Using the PHP Code Widget

WordPress allows us to add text and html in a normal text widget. But the author information to be shown, is not simple text, the content is dynamic. I needed to get information related to the author of the current post and present it. To achieve this, I installed and activated the PHP Code Widget Plugin. This plugin provided me with a widget, which allowed me to add php code. The widget then handled executing the php code and displaying the results.

PHP Code Widget

 

 

 

 

 

This plugin made my job really simple. I added the PHP Code Widget to the sidebar widgets. I then fetched and displayed the author information, using simple php code.

[pre]<?php
echo get_the_author_meta(first_name).’ ‘.get_the_author_meta(last_name).’<br/>’.get_the_author_meta(description);
?>[/pre]

Above is an example to display the author’s full name and biographical information. You can refer to the WordPress function get_the_author_meta for additional options.

How to List All Posts By the Author

In addition to author information, I wanted to display the links to other posts written by the same author. I was able to do this using the following:

[pre]$args = array( ‘author’ => get_the_author_meta(ID), ‘post__not_in’ => array( $post->ID ));
$author_other_posts = get_posts($args );
$posts_list = ‘<ul>’;
foreach ( $author_other_posts as $other_post ) {
$posts_list .= ‘<li><a href=”‘ . get_permalink( $other_post->ID ) . ‘”>’.$other_post ->post_title.'</a></li>’;
}
$posts_list.= ‘</ul>’;
echo $posts_list;[/pre]

Displaying Author Widgets only in Blog Posts

Of course it made sense to display the author widget only for blog posts and not other pages. This can be achieved by conditionally displaying the widget using the Widget Logic Plugin. The Widget Logic Plugin adds an extra field to every widget.

Widget Logic

You can use this field to specify a condition, which will control the display of the widget. The widget will be displayed only if the condition is evaluated to true.

Conclusion

Using these two simple plugins, PHP Code Widget and Widget Logic I was successfully able to create a customized author widget. Additionally, you could use simple CSS to style your widget. Do let me know if this article helped you create your own custom widget. If you had any questions, you could let me know in the comments section below.

 

Get a FREE Consultation

Let's build something that lasts.

Share what's on your mind — a clear brief, a half-formed idea, or just a sense that something needs to change. We'll listen first, ask the right questions, and point you toward what's actually worth building.

We take on a handful of projects each quarter,ones where we can truly make a difference.

  • Receive a human response within 24 hours
  • Get a detailed scope and quote upfront
  • We're happy to sign an NDA upon request

    Free 30-Min Strategy Call

    Your Name *

    Your Phone No *

    Work Email *

    Your Budget*

    Project Details *