Wordpress:如何为现有的Wordpress功能添加额外的HTML标签?

时间:2013-12-27 03:54:26

标签: php wordpress

我想知道如何在现有的Wordpress函数中添加title =“somecontent”标记。

以下是代码:

$author_id    = get_query_var( 'author' );
if(empty($author_id)) $author_id = get_the_author_meta('ID');
$alt          = get_the_author_meta('display_name');
$gravatar     = get_avatar( get_the_author_meta('email', $author_id), '81', '', $alt );
$name         = "<span class='author-box-name' ".avia_markup_helper(array('context' => 'author_name','echo'=>false)).">".get_the_author_meta('display_name', $author_id)."</span>";
$heading      = __("About",'avia_framework') ." ".$name;
$description  = get_the_author_meta('description', $author_id);

我想将标题标签专门添加到:

$gravatar     = get_avatar( get_the_author_meta('email', $author_id), '81', '', $alt );

如果你能指出方法来做这件事,那将非常有帮助,谢谢!

1 个答案:

答案 0 :(得分:1)

未经测试,但这应该让你开始。在 functions.php

add_filter('get_avatar', 'add_avatar_attributes', 10, 5);
function add_avatar_attributes($avatar, $id_or_email, $size, $default, $alt){
    $doc= new DOMDocument();
    $doc->loadHTML($avatar);
    $img = $doc->getElementsByTagName('img')->item(0);
    $img->setAttribute("title", "somecontent");
    return $doc->saveHTML();
}