E
E
Ewexon2021-03-20 23:40:51
PHP
Ewexon, 2021-03-20 23:40:51

How to make different images for og:image meta tag via php?

Online cinema. The site has 3 additional fields for images, and you need them to be displayed in meta tags.
Briefly about additional fields
poster - the field where the poster is loaded from the computer to the site server
poster-link - a link to the poster from another server
screens - a wide poster for social. networks and messengers, for example, for instagram, vk, viber, telegram.

screens is only used in TV shows.

In show.full.php I did

$social_tags['image'] = "/uploads/posts/" . $xfieldsdata['poster'];
$social_tags['image'] =  $xfieldsdata['poster-link'];
$social_tags['image'] =  $xfieldsdata['screens'];

But if you look at the code in movies and TV shows, it looks like this:
Series: Movie: The bottom line is that I want to do something that if the "screens" field is not filled, then the "poster" field is displayed, if it is not filled then the field " poster-link", and if this field is not filled, then either nothing was displayed, or a stub. I hope everything is clear, thanks in advance!
<meta property="og:image" content="x">
<meta property="og:image" content="">

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2021-03-21
@Ewexon

$social_tags['image'] =  $xfieldsdata['screens']
  ?? $xfieldsdata['poster-link']
  ?? ( $xfieldsdata['poster'] ? "/uploads/posts/".$xfieldsdata['poster'] : '/link/to/default.jpg' );

V
Valentyn, 2021-03-21
@rotarepmipoleved

It's very helpful to read the documentation.
Check for emptiness - https://www.php.net/manual/ru/function.empty.php
String length - https://www.php.net/manual/ru/function.mb-strlen.php
IF construct. ..ELSE...ELSEIF - https://www.w3schools.com/php/php_if_else.asp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question