Skip to content

Instantly share code, notes, and snippets.

@max-kk
Created April 25, 2016 12:17
Show Gist options
  • Save max-kk/e6e95ab4a98a2e7c9b218dc6959fcb82 to your computer and use it in GitHub Desktop.
Save max-kk/e6e95ab4a98a2e7c9b218dc6959fcb82 to your computer and use it in GitHub Desktop.
Add OG meta
<?php
function fv_wp_head_og() {
echo '<!-- fv_wp_head_og -->';
global $photo_obj;
// FIX for big images
$thumb_size = array(
'width' => 1400,
'height' => 1000,
'crop' => false,
);
$image = FvFunctions::getPhotoThumbnailArr($photo_obj, $thumb_size); //'full'
?>
<meta name="description" content="<?php echo sanitize_text_field($photo_obj->name) . ' / ' . sanitize_text_field($photo_obj->description); ?>"/>
<meta property="og:title" content="<?php echo sanitize_text_field($photo_obj->name); ?> / HABITAT:AARHUS"/>
<meta property="og:description" content="<?php echo sanitize_text_field($photo_obj->description); ?>"/>
<meta property="og:site_name" content="HABITAT:AARHUS"/>
<meta property="og:image" content="<?php echo $image[0] ?>"/>
<meta property="og:url" content="http://www.habitataarhus.dk<?php echo $_SERVER['REQUEST_URI']; ?>"/>
<?php
}
function fv_wp_title( $title, $sep ) {
global $photo_obj;
if ( !is_object($photo_obj) ) {
return $title;
}
return sanitize_text_field($photo_obj->name) . ' / HABITAT:AARHUS';
}
function fv_init_wp_head_og() {
global $photo_obj;
if ( !is_object($photo_obj) ) {
return false;
}
add_action('wp_head', 'fv_wp_head_og', 0);
//remove_action('su_head', array('SU_OpenGraph', 'head_tag_output'));
global $seo_ultimate;
remove_action( 'the_content', array( $seo_ultimate, 'template_head' ) );
remove_all_actions('su_head');
}
if ( !empty($_GET['photo']) ) {
add_action('init', 'fv_init_wp_head_og', 49);
add_filter( 'wp_title', 'fv_wp_title', 99, 2 );
global $photo_obj;
$photo_id = (int)$_GET['photo'];
global $photo_obj;
$photo_obj = ModelCompetitors::query()->findByPK($photo_id );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment