Need to Display Page Thumbnail URL (SMO Meta Tags)

Permalink
Hey all,

I need to echo out the page thumbnail's full URL for a particular meta tag. I plan to do this in the header of an existing website. Call me crazy, but I've tried everything I know to make this work but have been very unsuccessful.

Can someone please help me? Thanks all!

 
hutman replied on at Permalink Reply
hutman
This is what I have done in the past for 5.6, this code goes into a package controller

public function on_start() {
            Events::extend('on_before_render', 'ClassName', 'on_before_render_handler', DIR_PACKAGES.'/package_name/controller.php');
        }
        public function on_before_render_handler(){
            $view = View::getInstance();
            $c = Page::getCurrentPage();
            //don't do this if we're in the dashboard or don't have a valid page
            if(is_object($c) && !$c->isError() && !$c->isSystemPage()){
                $thumbnailImage = $c->getAttribute('thumbnail_image');
                if($thumbnailImage ){
                    $view->addHeaderItem('<meta property="og:image" content="'.$thumbnailImage ->getApprovedVersion()->getURL().'" />');
                }
            }
        }
marrow replied on at Permalink Reply
Hutman,

Thanks for the quick reply. I really appreciate it. I probably should've mentioned that this is for a 5.7.5.6 website. My apologies.

Is there anything that can be done for this version?
hutman replied on at Permalink Reply
hutman
This should work for that version in the controller

use Page;
use Events;
use View;
public function on_start(){    
    Events::addListener('on_before_render', function () {
        $view = View::getInstance();
        $c = Page::getCurrentPage();
        //don't do this if we're in the dashboard or don't have a valid page
        if(is_object($c) && !$c->isError() && !$c->isSystemPage()){
            $thumbnailImage = $c->getAttribute('thumbnail');
            if($thumbnailImage){
                $view->addHeaderItem('<meta property="og:image" content="'.$thumbnailImage->getURL().'" />');
            }
        }
    });
marrow replied on at Permalink Reply
I honestly do not know where to place the PHP. I'm not a developer. Isn't there a way to place this using just the header_required.php or in the header_top.php as all pages have thumbnails?
hutman replied on at Permalink Best Answer Reply
hutman
You can put this in your header_top.php in your theme by just doing this

$c = Page::getCurrentPage();
$thumbnailImage = $c->getAttribute('thumbnail');
if($thumbnailImage){
   echo '<meta property="og:image" content="'.$thumbnailImage->getURL().'" />';
}
marrow replied on at Permalink Reply
Hutman!!!!!! You are awesome. Thank you so much. That did the trick perfectly.
MrKDilkington replied on at Permalink Reply
MrKDilkington
@foundry

In addition to hutman's answer, there is an excellent free add-on for adding Open Graph metadata to your pages.

Open Graph Tags Lite by hissy
https://www.concrete5.org/marketplace/addons/open-graph-tags-lite1...