Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Shows how to set up a template for including meta tags in a Participants Database singe record page when using the Image Expansion add-on
* @name pdb single opengraph template
* @version 0.1
* template for printing opengraph meta tags
* this variant is for use with the Participants Database Image Expansion add-on
* simplified information on using social media meta tags can be found here:
* you will need to adapt this to the data fields you are using and how you are using them,
* please don't expect this to work for you without modifying it to match your setup!
// first check to make sure we have a record loaded
if ( $this->participant_id > 0 ) :
if ( ! function_exists( 'get_attachment_url_by_slug' ) ) :
* provides the full URL to a media file, given the media item name (or slug)
* @param string $slug name of the media item
* @return string URL to the media file
function get_attachment_url_by_slug( $slug ) {
$args = array(
'post_type' => 'attachment',
'name' => sanitize_title($slug),
'posts_per_page' => 1,
'post_status' => 'inherit',
$_header = get_posts( $args );
$header = $_header ? array_pop($_header) : null;
return $header ? wp_get_attachment_url($header->ID) : '';
// set up the template object
$record = new PDb_Template( $this );
<!-- Start Participants Database Meta Tags -->
<?php // this will be shown as the headline of the share ?>
<meta property="og:title" content="<?php echo $record->get_value('first_name') . ' ' . $record->get_value('last_name') ?>">
<?php // this will typically appear under the headline, it should be a short descriptive text ?>
<meta property="og:description" content="<?php echo $record->get_value('description') ?>">
<?php // this needs to be the URL to the image to show in the share ?>
<meta property="og:image" content="<?php echo get_attachment_url_by_slug( $record->get_value('photo') ) ?>">
<?php // this is the URL of the current page ?>
<meta property="og:url" content="<?php echo 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ?>">
<?php // for twitter, add a caption. This could be the same as the title or description ?>
<meta name="twitter:card" content="<?php echo $record->get_value('photo_caption') ?>">
<!-- End Participants Database Meta Tags -->
<?php endif;

This comment has been minimized.

Copy link
Owner Author

xnau commented Jul 18, 2018

To create a share link, you'll need a custom template for your single record display as well. In that template, put a link like this:

<a href="<?php echo urlencode( Participants_Db::single_record_url( $this->participant_id ) ) ?>">Share on Facebook</a>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.