Topic: Meta (if, else)

Hi Support Team and members,

I’ve a request, I use this code for meta :

<?PHP require_once "../info/cn_api.php";$entry = cn_api_get_entry();if ($entry['t']){$header_title = ($entry['t']);$short_story = (substr($entry['f'],0,160));$tagline = ($entry['tg']);$category_name = ( join(' / ', $entry[':cot']) );$trunc_short = trim( (strip_tags($short_story)) );$entry['mf']['photo'];$entry['mf']['photoxxl'];$entry['mf']['video'];$entry['mf']['videoxxl'];$entry['mf']['daily'];$entry['mf']['dailyxxl'];$entry['mf']['twitter'];}echo '<title>'.$header_title.' - '.$category_name.'</title>';echo '<meta name="description" content="'.$trunc_short.'"/>';echo '<meta name="news_keywords" content="'.$category_name.','.$tagline.'"/>';echo '<meta property="og:title" content="'.$header_title.'"/>';echo '<meta property="og:description" content="'.$trunc_short.'"/>';echo '<meta property="og:image" content="'.$entry['mf']['photo'].'"/>';echo '<meta property="og:image" content="'.$entry['mf']['photoxxl'].'"/>';echo '<meta property="og:image" content="http://img.youtube.com/vi/'.$entry['mf']['video'].'/hqdefault.jpg"/>';echo '<meta property="og:image" content="http://img.youtube.com/vi/'.$entry['mf']['videoxxl'].'/hqdefault.jpg"/>';echo '<meta property="og:image" content="http://www.dailymotion.com/thumbnail/video/'.$entry['mf']['daily'].'"/>';echo '<meta property="og:image" content="http://www.dailymotion.com/thumbnail/video/'.$entry['mf']['dailyxxl'].'"/>';echo '<meta name="twitter:card" content="summary_large_image"/>';echo '<meta property="twitter:image:src" content="'.$entry['mf']['photo'].'"/>';echo '<meta property="twitter:image:src" content="'.$entry['mf']['photoxxl'].'"/>';echo '<meta property="twitter:image:src" content="http://img.youtube.com/vi/'.$entry['mf']['video'].'/hqdefault.jpg"/>';echo '<meta property="twitter:image:src" content="http://img.youtube.com/vi/'.$entry['mf']['videoxxl'].'/hqdefault.jpg"/>';echo '<meta property="twitter:image:src" content="http://www.dailymotion.com/thumbnail/video/'.$entry['mf']['daily'].'"/>';echo '<meta property="twitter:image:src" content="http://www.dailymotion.com/thumbnail/video/'.$entry['mf']['dailyxxl'].'"/>';echo '<meta property="twitter:title" content="'.$header_title.'"/>';echo '<meta name="twitter:creator" content="'.$entry['mf']['twitter'].'"/>';echo '<meta property="twitter:description" content="'.$trunc_short.'"/>';echo '<link rel="image_src" href="'.$entry['mf']['photo'].'"/>';echo '<link rel="image_src" href="'.$entry['mf']['photoxxl'].'"/>';echo '<link rel="image_src" href="http://img.youtube.com/vi/'.$entry['mf']['video'].'/hqdefault.jpg"/>';echo '<link rel="image_src" href="http://img.youtube.com/vi/'.$entry['mf']['videoxxl'].'/hqdefault.jpg"/>';echo '<link rel="image_src" href="http://www.dailymotion.com/thumbnail/video/'.$entry['mf']['daily'].'"/>';echo '<link rel="image_src" href="http://www.dailymotion.com/thumbnail/video/'.$entry['mf']['dailyxxl'].'"/>';echo '<meta itemprop="image" content="'.$entry['mf']['photo'].'"/>';echo '<meta itemprop="image" content="'.$entry['mf']['photoxxl'].'"/>';echo '<meta itemprop="image" content="http://img.youtube.com/vi/'.$entry['mf']['video'].'/hqdefault.jpg"/>';echo '<meta itemprop="image" content="http://img.youtube.com/vi/'.$entry['mf']['videoxxl'].'/hqdefault.jpg"/>';echo '<meta itemprop="image" content="http://www.dailymotion.com/thumbnail/video/'.$entry['mf']['daily'].'"/>';echo '<meta itemprop="image" content="http://www.dailymotion.com/thumbnail/video/'.$entry['mf']['dailyxxl'].'"/>';if ($_GET['id']) echo '<meta property="og:url" content="http://'.$_SERVER['SERVER_NAME'].''.$_SERVER['REQUEST_URI'].'"/>';if ($_GET['id']) echo '<meta name="twitter:url" content="http://'.$_SERVER['SERVER_NAME'].''.$_SERVER['REQUEST_URI'].'"/>';if ($_GET['id']) echo '<meta itemprop="url" content="http://'.$_SERVER['SERVER_NAME'].''.$_SERVER['REQUEST_URI'].'"/>';if ($_GET['id']) echo '<link rel="canonical" href="http://'.$_SERVER['SERVER_NAME'].''.$_SERVER['REQUEST_URI'].'"/>'; ?>

It’s works, no problem but when an article is shared, for example Facebook, the OG image can be with the tag photo, photoxxl, video or videoxxl. It means that at once, 3 of 4 meta are empty and the debugger Facebook (https://developers.facebook.com/tools/debug) said there is empty meta (error). Of course it’s normal but is it a possibility to write something like that in meta :

if…
else…

Best regards.

Re: Meta (if, else)

up https://cutephp.com/forum/style_emoticons/default/smile.gif

Re: Meta (if, else)

Do you want the meta tags to simply not be displayed when they are empty, or do you want to replace empty meta tags with some sort of a template?

Best regards,
CN Support team

Re: Meta (if, else)

Hi support Team,

Yes first solution :  the meta tags to simply not be displayed when they are empty

Best regards.

5 (edited by 2014-12-11 08:54:50)

Re: Meta (if, else)

Hi support Team,

Yes first solution :  the meta tags to simply not be displayed when they are empty

Best regards.

...
if( !empty($entry['mf']['photo'] ))
{
     echo '<meta property="og:image" content="'.$entry['mf']['photo'].'"/>';
}
if( !empty($entry['mf']['photoxxl'] ))
{
     echo '<meta property="og:image" content="'.$entry['mf']['photoxxl'].'"/>';
}
...


To tackle such problems faster, make yourself familiar with PHP documentation.

Best regards,
CN Support team

Re: Meta (if, else)

Thank you Support Team, it's perfect.