Get image path (src) from image block in a Known Area

Permalink
HI All,
The underlying issue is I would like to provide an "image" for the SEO Structured Data andhttps://search.google.com/structured-data/testing-tool... says image is missing.

I know the page has an area for the user to drop an image block for the logo. I would like to include that path as part of the data,

I know the area name. How do I check for an image block? If found get the filename of the image? (In PHP code at the Page Controller Level.

Thanks,
Sean

 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi SeanDevoy,

Are you trying to use an Open Graph protocol og:image? Where each page has its own unique image?

Example:
<meta property="og:image" content="http://mysite.com/images/my-page-image.jpg" />

If so, I recommend using the Open Graph Tags Lite add-on by hissy. It will handle all of this for you.
https://www.concrete5.org/marketplace/addons/open-graph-tags-lite1/...
SeanDevoy replied on at Permalink Reply
Nope sorry, nothing to do with Open Graph.

This is the relatively new "structured data" schema that "tells search engines what your data is".

See here:
https://developers.google.com/search/docs/guides/intro-structured-da...

However, that has nothing to do with my question. I am really just trying to find a way to get the path to an image in an image block in a page area.

Thanks,
Sean
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
@SeanDevoy

You can try this:
<?php
// get the area object using the area name
$areaObject = $c->getArea('Header Site Title');
// get the blocks in the area object
$areaBlocks = $areaObject->getAreaBlocks();
// loop through the array of area blocks
foreach ($areaBlocks as $block) {
    // if the current block has the block handle of "image"
    if ($block->btHandle == 'image') {
        // get the block's instance
        $blockInstance = $block->getInstance();
        // use the Image block controller getFileID() method to see if there is a selected image
        if ($blockInstance->getFileID()) {
            // if there is a selected image, get its file ID
            $fileID = $blockInstance->getFileID();
SeanDevoy replied on at Permalink Reply
Perfect!

Thanks so much.
siton replied on at Permalink Reply
siton
please mark as "best answer" for future searches.