### [如何在WordPress 文章未尾自动添加一个作者信息框](https://www.prosaas.cn/article/9334) **Published:** 2019-12-20T05:31:35 **Author:** 5201314 **Excerpt:** 下面由WordPress教程栏目给大家介绍在WordPress 文章未尾自动添加一个作者信息框的方法,希望对需… 下面由**WordPress教程**栏目给大家介绍在WordPress 文章未尾自动添加一个作者信息框的方法,希望对需要的朋友有所帮助!  如果想在**WordPress**文章的末尾,添加文章作者的相关信息,下面一段代码可以方便在文章中添加一个作者的信息框。 将代码添加到当前主题functions.php中: function wp\_author\_info\_box( $content ) { global $post; // 检测文章与文章作者 if ( is\_single() && isset( $post->post\_author ) ) { // 获取作者名称 $display\_name = get\_the\_author\_meta( 'display\_name', $post->post\_author ); // 如果没有名称,使用昵称 if ( empty( $display\_name ) ) $display\_name = get\_the\_author\_meta( 'nickname', $post->post\_author ); // 作者的个人信息 $user\_description = get\_the\_author\_meta( 'user\_description', $post->post\_author ); // 获取作者的网站 $user\_website = get\_the\_author\_meta('url', $post->post\_author); // 作者存档页面链接 $user\_posts = get\_author\_posts\_url( get\_the\_author\_meta( 'ID' , $post->post\_author)); if ( ! empty( $display\_name ) ) $author\_details = '
'; if ( ! empty( $user\_description ) ) // 作者头像 $author\_details .= ''; $author\_details .= ''; } else { // 如果作者没有填写网站则不显示网站链接 $author\_details .= ''; } // 在文章后面添加作者信息 $content = $content . ''; } return $content; } // 添加过滤器 add\_action( 'the\_content', 'wp\_author\_info\_box' ); // 允许HTML remove\_filter('pre\_user\_description', 'wp\_filter\_kses'); 再将配套的CSS添加到主题样式文件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; } 以上就是如何在WordPress 文章未尾自动添加一个作者信息框的详细内容,更多请关注知企PROSAAS其它相关文章! **Tags:** php, WordPress **Categories:** WordPress ---