Created
September 30, 2021 16:20
-
-
Save matdave/71e594764e7a8000755805b32652abee to your computer and use it in GitHub Desktop.
Simple OG Image- MODX output modifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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