Skip to content

Instantly share code, notes, and snippets.

@matdave
Created September 30, 2021 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matdave/71e594764e7a8000755805b32652abee to your computer and use it in GitHub Desktop.
Save matdave/71e594764e7a8000755805b32652abee to your computer and use it in GitHub Desktop.
Simple OG Image- MODX output modifier
<?php
if(empty($input)) return;
$url = rtrim($modx->getOption('site_url'), '/').'/'.ltrim($input,'/');
echo "<meta name=\"image\" property=\"og:image\" content=\"$url\" />";
$path = rtrim($modx->getOption('base_path'), '/').'/'.ltrim($input,'/');
$size = @getimagesize($path);
if ($size) {
$width = $size[0];
$height = $size[1];
echo "<meta property=\"og:image:width\" content=\"$width\" />";
echo "<meta property=\"og:image:height\" content=\"$height\" />";
}
$mime = @mime_content_type($path);
if ($mime) {
echo "<meta property=\"og:image:type\" content=\"$mime\" />";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment