Thread tagged as: Question, Gallery

Gallery album social sharing image.

I'm attempting to pull an image from the album.php page into page attributes for social media sharing, without success.

The template code for the image I'm after is thus:

<perch:gallery id="image" type="image" key="two" width="1600" />

I placed the following in a page attributes file to no avail.

<meta property="og:image" content="<perch:pages id="domain" /><perch:gallery id="two" />" />

I've also unsuccessfully tried the following:

This in a header.php file (just showing the relevant bits here);

$domain = 'https://'.$_SERVER["HTTP_HOST"];
$sharing_image = perch_gallery_image(perch_get('id'), array(
'skip-template' => 'true',


Then this in a page attributes file;

<meta property="og:image" content="<perch:pages id="domain" /><perch:pages id="sharing_image" />" />

Still trying to figure this out myself but would appreciate any pointers. Thanks.

Mark Phoenix

Mark Phoenix 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you break it down, which part isn't working?

Hi Drew. Seems to me the problem is here as I get a result when I hard code an id without the array, though the result is echoed onto the page though and doesn't transfer to the variable. Apologies if this is ovbious, having a sub-optimal day.

$sharing_image = perch_gallery_image(perch_get('id'), array(
'skip-template' => 'true',
Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the value of id on your query string?

It's /gallery/album.php?s=gallery-one. I'm using a slider so I'm outputting all the images in an album to the page with;

    if(perch_get('s')) {
      perch_gallery_album_images(perch_get('s'), array(
               'template'   =>'gallery-page.html'
    } ?>

Should I be/can I use that to retrive a single image from the album?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you should be able to set a count in the options to reduce it to one item.

Great, that's fixed it.

In case it's useful to anyone, header code is;

$sharing_image =  perch_gallery_album_images(perch_get('s'), array(
'template' =>'sharing-image.html',
'count' => 1,
), true);

Gallery sharing-image.html template is just;

<perch:gallery id="three" />

Thanks Drew