I have Panels set up to display node pages for my main content types, all of which have images.

I've enabled Open Graph meta tags to work with Panels, as well as each of the relevant content types, and it does produce og:title and og:site_name tags, but nothing for og:image. Is there any way to set it up so that the node being displayed in the Panel gets set as og:image?

Thanks,
D.

Comments

hiddentao’s picture

It only displays the og:image tag if the given node has an image attached. This can be via an Image CCK field or via a HTML img tag in the node's body content. The latest release of this module contains the option of providing a "fallback" image to use for og:image if a node doesn't have one available. Try setting that to something and see if it works.

hiddentao’s picture

Status: Active » Postponed (maintainer needs more info)
leovw’s picture

I am having a similar issue:

Not entirely sure whether it is an Open Graph meta tags issue or a Panels issue...

I have overridden most of my node types with panels and they do not show any of the open graph tags unless I disable the panel type and view them as plain old nodes??

Any help would be very much appreciated as getting this working is mission critical!

leovw’s picture

Version: 6.x-1.4 » 6.x-1.5
Status: Postponed (maintainer needs more info) » Active

I am reposting so I can reopen the issue and hopefully someone can shed some light on the problems with panels...

I have overridden most of my node types with panels and they do not show any of the open graph tags unless I disable the panel type and view them as plain old nodes??

Does anybody have any idea why this may be happening?

Thanks, Leo

leovw’s picture

Category: support » bug

This is still a problem - Currently Open Graph meta tags doesn't seem to be compatible with panels!!

I have been bugging merlinofchaos on the panels issue queue about this too and he has offered some possible solutions:

You could probably implement hook_ctools_render_alter() and do a node_invoke('view') on the node there, but that's kind of a pain in the butt since you've got to dig the node out of the context. It's not THAT hard, mind you.

Heres the link - > http://drupal.org/node/1155930#comment-4474014

I am happy to help although my PHP is currently very basic

Thanks

leovw’s picture

I used this code which I borrowed from another issue queue which seems to do the job:

/**
* Implementation of hook_ctools_render_alter().
*
* When using Panels module (CTools Pagemanager), hook_nodeapi (view) is not
* being called. Use hook_ctools_render_alter() to start the
* menutrails_nodeapi procedure.
*
* @see http://drupal.org/node/362065
*/

function opengraph_meta_ctools_render_alter($info, $page, $args, $contexts, $task, $subtask) {
  if ($task['admin path'] == 'node/%node' && $page) {
    // Set title from node title as is unset for some reason..
    drupal_set_title($contexts['argument_nid_1']->title);
    // Activate menutrails
    opengraph_meta_nodeapi($contexts['argument_nid_1']->data, 'view', NULL, $page);
  }
}
dccircuit’s picture

leovw, Where would the code in #6 go? If I add it to the .module file, I get duplicated meta-tags (without the correct og:image -- just the fallback, still)... Is it supposed to replace another function?

Thanks.

(My issue is similar to others on the page... I have used Panels to override the display of several of my node-types which have a CCK image field... When viewing without the panel override, the correct image is selected. When I enable the override, the image selected is always my "fallback" image.)

tararowell’s picture

I used this simple solution to get the og:url to show in the meta data:

In the opengraph_meta.common.inc I added a hook:

public function harvest_images_from_node($node) {
    // extract image fields
    $ret = array();
    $this->_extract_image_fields_from_node((array)$node, $ret);
    // extract all images from body content
    if (!empty($node->body)) {
      libxml_use_internal_errors(TRUE); // turn off libxml errors for now
      $doc = new DOMDocument();
      $doc->loadHTML($node->body);
      $list = $doc->getElementsByTagName('img');
      for ($i=0; $list->length > $i; ++$i) {
        $item = $list->item($i);
        if ($item->hasAttribute('src')) {
          $attrval = $item->getAttribute('src');
          if (!empty($attrval))
            $ret[] = $attrval;
        }
	
    }
+	  //add hook so that drupal can find an image in a CCK field
+	  drupal_alter('opengraph_meta_images', $ret, $node);
	  		  
      libxml_use_internal_errors(FALSE); // turn libxml errors back on
    }

    return $ret;
   }
  }

Then used a function like this to let the module know that my image was not in the body field, but in a separate CCK field:

function (module name)_opengraph_meta_images_alter(&$ret, $node) {
     if (!empty($node->field_main_photo)){
             libxml_use_internal_errors(TRUE); // turn off libxml errors for now
             $node_image = node_load($node->field_main_photo[0]['nid']);
             $fb_thumb = $node_image->field_image[0]['filepath'];
             $ret[] = $fb_thumb;
              }
} 

I am certainly open to suggestions for optimizing this in any way, but it works.
HOWEVER, I still find that FB ignores the og tags sometimes!

clint.beacock’s picture

I have a panel that's loading a node from a url arugument. I ended up modifying the $vars['head'] variable using the hook_preprocess_page function in template.php.

Here's the code:

//add opengraph metatags to my panel page
$display = panels_get_current_page_display();
if (isset($display) && $display != null){
	foreach($display->content as $panel){
		if ($panel->panel=='product_view'){  // You'll need to change this to target your panel name
			$pnode=node_load($display->args[0]);
			$og_meta=$pnode->opengraph_meta;
			foreach($og_meta as $prop => $content){
				if(isset($content) && $content != ''){
					$vars['head'] .= '<meta property="og:'.$prop.'" content="'.(($prop=='image'||$prop=='url')?'http://'.$_SERVER['HTTP_HOST'].base_path().$content:$content).'" />'."\n";
				}
			}
		}
	}
}

The key is using panels_get_current_page_display()
Once you load that into a variable, you can do whatever you like.

Hope this helps someone.

windm’s picture

Hi there,

to be honest, I expected to get an easier solution with the module... ;-)

My "simple" idea was to define a fixed CCK-field for each content-type to be the "representing image"... I don´t want the users to decide about if to use img #1 or #2 or whatever to be the one to be handed over as the node-image. I only want to define that e.g. the CCK-field "logo" is the one for content-type "event", the CCK-field "photo1" is the one for content-type "addressbook" and so on (for approx. 10 content types).

Do I need to use the function from #8 several times for each content-type? Being not familiar with any kind of code... I also need to ask: How would that impact the code and where do I need to paste the "function"?

Apart from that, I also use Panels+Views to display the nodes... so should I better try #9??

Or better something out of #8 and #9??

bradjones1’s picture

Category: bug » support

Marking this support. I think this would also apply to the D7 version from what I can tell.

mattwmc’s picture

Issue summary: View changes

Not working for me in Panels, either.

Actually it seems as if lots of modules don't work in Panels. :(

mattwmc’s picture

So no fix?

Guess, I'll just remove the mod.

torotil’s picture

Status: Active » Closed (won't fix)

Hi,

I'm the new maintainer of opengraph_meta. Sorry for the long silence in the issue queue.

Sadly I don't have the resources to care for the Drupal 6 version. Unless and until someone steps up to maintain it I'm therefore closing all D6 issues as WONTFIX.

Feel free to re-open the issue if it is still valid in one of the Drupal 7 branches.

Thanks!