The method of automatically adding an author information box at the end of a WordPress article
This article mainly introduces the method of automatically adding an author information box at the end of WordPress articles. The article is very detailed and has certain reference value. Interested friends must read it!
If you want to add information about the author of a WordPress article at the end of the article, here is a code that makes it easy to add an author infobox to the article.
Add code to the current topic functions.php:
function wp_author_info_box( $content ) { global $post; //detect articles and article authors if ( is_single() && isset( $post->post_author ) ) { //Get author name $display_name = get_the_author_meta( 'display_name', $post->post_author ); //If there is no name, use a nickname if ( empty( $display_name ) ) $display_name = get_the_author_meta( 'nickname', $post->post_author ); //Author's personal information $user_description = get_the_author_meta( 'user_description', $post->post_author ); //Get the author's website $user_website = get_the_author_meta('url', $post->post_author); //Author Archive page link $user_posts = get_author_posts_url( get_the_author_meta( 'ID' , $post->post_author)); if ( ! empty( $display_name ) ) $author_details = 'about'. $display_name . ''; if ( ! empty( $user_description ) ) //Author profile $author_details .= '' . get_avatar( get_the_author_meta('user_email') , 90 ) . nl2br( $user_description ). ''; $author_details .= 'view'. $display_name . 'all articles'; //Check if the author has a website in his profile if ( ! empty( $user_website ) ) { //Show author's website link $author_details .= ' |Website'; } else { //If the author does not fill in the website, the website link will not be displayed $author_details .= ''; } //add author information to the end of the article $content = $content . '' . $author_details . ''; } return $content;}//Add filter add_action ('the_content','wp_author_info_box');//Allow HTMLremove_filter ('pre_user_description','wp_filter_kes'); then add matching CSS to theme style file style.css: .author-bio-section { background: #fff; float: left; width: 100%; margin: 10px 0; padding: 15px; border: 1px dashed #ccc;}.author-name { font-size: 15px; font-weight: bold; margin: 0 0 5px 0;}.author-details img { float: left; width: 48px; height: auto; margin: 5px 15px 0 0;} The above is all about automatically adding an author info box at the end of a WordPress article. Thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!