Php 如何为wordpress制作OG图像
如何为WordPress制作og:image?这是我的密码Php 如何为wordpress制作OG图像,php,html,Php,Html,如何为WordPress制作og:image?这是我的密码 <meta name="og:image" content="<?php // if home page og image $ogImage="https://www.example.com/test.jpg" if (is_home()) {echo $ogImage;} // if single page og image elseif (is_single() || is_pag
<meta name="og:image" content="<?php
// if home page og image
$ogImage="https://www.example.com/test.jpg"
if (is_home()) {echo $ogImage;}
// if single page og image
elseif (is_single() || is_page()) {
$ogImage = get_post_meta($post->ID, 'og_image', true);}
else{echo $ogImage;}
?>" />
您忘记添加代码>在末尾$ogImage
:
<meta name="og:image" content="<?php
// if home page og image
$ogImage="https://www.example.com/test.jpg"; // edit here
if (is_home()) {echo $ogImage;}
// if single page og image
elseif (is_single() || is_page()) {
$ogImage = get_post_meta($post->ID, 'og_image', true);}
else{echo $ogImage;}
?>" />
您忘记添加代码>在末尾$ogImage
:
<meta name="og:image" content="<?php
// if home page og image
$ogImage="https://www.example.com/test.jpg"; // edit here
if (is_home()) {echo $ogImage;}
// if single page og image
elseif (is_single() || is_page()) {
$ogImage = get_post_meta($post->ID, 'og_image', true);}
else{echo $ogImage;}
?>" />
你好,谢谢@Dmitry关于你的回答,我很感激。您更正了关于添加“;”的问题,即不再显示白色屏幕。但是为什么og:image在我查看文章时是空白的?当im没有在文章pos自定义段中创建“og_图像”时,必须具有此功能。我的代码错了吗?你好,谢谢@Dmitry关于你的答案,我很感激。您更正了关于添加“;”的问题,即不再显示白色屏幕。但是为什么og:image在我查看文章时是空白的?当im没有在文章pos自定义段中创建“og_图像”时,必须具有此功能。我的代码错了吗?您没有回显代码的elseif部分中的任何内容,只是指定了一个值。您没有回显代码的elseif部分中的任何内容,只是指定了一个值。