繁体   English   中英

Wordpress:如何向现有的Wordpress函数添加额外的HTML标签?

[英]Wordpress: How Do I Add Extra HTML Tags To Existing Wordpress Functions?

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

这是代码:

$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);

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

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

如果您能指出我执行此操作的方法,将非常有帮助,谢谢!

未经测试,但这应该可以帮助您入门。 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();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM