Php Wordpress:如何向现有Wordpress函数添加额外的HTML标记?
我想知道如何将title=“somecontent”标记添加到现有的Wordpress函数中 代码如下:Php Wordpress:如何向现有Wordpress函数添加额外的HTML标记?,php,wordpress,Php,Wordpress,我想知道如何将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_aut
$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);
如果你能告诉我做这件事的方法,那将非常有帮助,谢谢 未经测试,但这应该可以让您开始。在functions.php中:
我知道你要用它去哪里,尽管有些代码对我来说非常陌生。不幸的是,它不起作用。所有标签都已经存在,我只需要添加标题标签。我也可以编辑核心,如果更简单的话,不需要将其放入functions.php。下面是错误消息:警告:第89行/home/content/24/11588624/html/wp/wp content/themes/vaseo/functions.php中的add_avatar_attributes()缺少参数2警告:add_avatar_attributes()缺少参数3第89行的/home/content/24/11588624/html/wp/wp content/themes/vaseo/functions.php警告:第89行的/home/content/24/11588624/html/wp content/themes/vaseo/functions.php中添加化身属性()缺少参数4警告:添加化身属性()缺少参数5在第89行的/home/content/24/11588624/html/wp/wp content/themes/vaseo/functions.php中编辑。现在试试看。您绝对没有理由编辑核心代码。如果你看一下我给你的代码,你会发现我们在图像标记中添加了一个title属性,如果你想正确地进行操作,它需要进入functions.php。这非常有效!感谢您的帮助,我将继续阅读我的PHP书籍:)这是上述代码的输出,我需要将标题标记添加到:''许多人无法理解这个问题,因为您需要的可能不是标记,而是属性。你能证实这一点吗?
$gravatar = get_avatar( get_the_author_meta('email', $author_id), '81', '', $alt );
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();
}