我过去在这里问过一些问题,每个人都非常热情地回答我。我大概是个“初学者”。预先感谢您。
所以我正在使用 WordPress 的 Rank Math SEO 插件的高级版本。关于 SCHEMA 创建功能:问题是该插件从 gravatar 个人资料中提取作者图像(并且我不使用 gravatar 登录我的 WordPress 网站)。我想在 Rank Math php 文件中对作者的图像 URL 进行硬编码(我是我网站上的唯一作者,所以没关系)。网站是 https://mbastory [dot] builders
这是获取图像 URL 的 php 片段
private function add_image( &$entity, $author_id, $jsonld ) {
$entity['image'] = [
'@type' => 'ImageObject',
'@id' => get_avatar_url( $author_id ),
'url' => get_avatar_url( $author_id ),
'caption' => get_the_author(),
];
$jsonld->add_prop( 'language', $entity['image'] );
}
我认为这可能有效。我想打印 url 并在其末尾附加 #author 作为 @id,然后我想显示该 URL 的图像。
private function add_image( &$entity, $author_id, $jsonld ) {
$entity['image'] = [
'@type' => 'ImageObject',
'@id' => echo 'https//mbastory.builders/wp-content/uploads/Leah-Derus-Circular-Light-Grey-500px.png#author',
'url' => $filepath= '\wp-content\uploads\Leah-Derus-Circular-Light-Grey-500px.png'; echo '<img src="'.$filepath.'">',
'caption' => get_the_author(),
];
$jsonld->add_prop( 'language', $entity['image'] );
}
** 这看起来对吗?**
毫不奇怪(至少对我来说)...我的代码出现了一个巨大的严重错误...
除了修改插件文件之外,您还可以使用 get_avatar_url 过滤器挂钩从主题的functions.php 文件中更改它,例如:
function wp99835_filter_get_avatar_url( $url, $id_or_email, $args ) {
$url = 'https//mbastory.builders/wp-content/uploads/Leah-Derus-Circular-Light-Grey-500px.png';
return $url;
}
add_filter( 'get_avatar_url', 'wp99835_filter_get_avatar_url', 10, 3 );