I need to add xmlns:og="http://opengraphprotocol.org/schema/" to all pages as per OpenGraph Metatags at http://drupal.org/project/opengraph_meta

There's a post about adding this nonsense (I hate Facebook) for IE, but I don't see where it would need to go in the html.tpl.php file (or even if that's where it would go) for all browsers. I've copied the .tpl file to the subtheme folder, so all I need to know is where to paste the darn thing - sorry for being so dense... thank you for your help and for this awesome theme system!

Comments

Jeff Burnz’s picture

Status: Active » Fixed

At provides a variable you can add to for sticking new attributes in the html element, so in preprocess do this:

function at_commerce_preprocess_html(&$vars) {
  // Inject the opengraph XML namespace attribute into the html element
  $vars['html_attributes_array']['xmlns:og'][] = 'http://opengraphprotocol.org/schema/';
}
bcobin’s picture

Thanks so much, Jeff.

So template.php would look like the below, right? (This is a live site, so I want to be careful here.)

/**
 * Override or insert variables into the html template.
 */
function at_commerce_preprocess_html(&$vars) {

  global $theme_key;

  $theme_name = 'at_commerce';
  $path_to_theme = drupal_get_path('theme', $theme_name);
  
    // Inject the opengraph XML namespace attribute into the the html element
  $vars['html_attributes_array']['xmlns:og'][] = 'http://opengraphprotocol.org/schema/';
}

  // Add a class for the active color scheme
  if (module_exists('color')) {
    $class = check_plain(get_color_scheme_name($theme_key));
    $vars['classes_array'][] = 'color-scheme-' . drupal_html_class($class);
  }

  // Add class for the active theme
  $vars['classes_array'][] = drupal_html_class($theme_key);

  // Add browser and platform classes
  $vars['classes_array'][] = css_browser_selector();

  // Add theme settings classes
  $settings_array = array(
    'body_background',
    'header_layout',
    'menu_bullets',
    'main_menu_alignment',
    'corner_radius_form_input_text',
    'corner_radius_form_input_submit',
  );
  foreach ($settings_array as $setting) {
    $vars['classes_array'][] = at_get_setting($setting);
  }

  // Special case for PIE htc rounded corners, not all themes include this
  if (at_get_setting('ie_corners') == 1) {
    drupal_add_css($path_to_theme . '/css/ie-htc.css', array(
      'group' => CSS_THEME,
      'browsers' => array(
        'IE' => 'lte IE 8',
        '!IE' => FALSE,
        ),
      'preprocess' => FALSE,
      )
    );
  }

  // Custom settings for AT Commerce
  // Content displays
  $show_frontpage_grid = at_get_setting('content_display_grids_frontpage') == 1 ? TRUE : FALSE;
  $show_taxopage_grid = at_get_setting('content_display_grids_taxonomy_pages') == 1 ? TRUE : FALSE;
  if ($show_frontpage_grid == TRUE || $show_taxopage_grid == TRUE) {drupal_add_js($path_to_theme . '/scripts/equalheights.js');}
  if ($show_frontpage_grid == TRUE) {
    $cols_fpg = at_get_setting('content_display_grids_frontpage_colcount');
    $vars['classes_array'][] = $cols_fpg;
    drupal_add_js($path_to_theme . '/scripts/eq.fp.grid.js');
  }
  if ($show_taxopage_grid == TRUE) {
    $cols_tpg = at_get_setting('content_display_grids_taxonomy_pages_colcount');
    $vars['classes_array'][] = $cols_tpg;
    drupal_add_js($path_to_theme . '/scripts/eq.tp.grid.js');
  }

  // Do stuff for the slideshow
  if (at_get_setting('show_slideshow') == 1) {
    // Add some js and css
    drupal_add_css($path_to_theme . '/css/styles.slideshow.css', array(
      'preprocess' => TRUE,
      'group' => CSS_THEME,
      'media' => 'screen',
      'every_page' => TRUE,
      )
    );
    drupal_add_js($path_to_theme . '/scripts/jquery.flexslider-min.js');
    drupal_add_js($path_to_theme . '/scripts/slider.options.js');

    // Add some classes to do evil hiding of elements with CSS...
    if (at_get_setting('show_slideshow_navigation_controls') == 0) {
      $vars['classes_array'][] = 'hide-ss-nav';
    }
    if (at_get_setting('show_slideshow_direction_controls') == 0) {
      $vars['classes_array'][] = 'hide-ss-dir';
    }

    // Write some evil inline CSS in the head, oh er..
    $slideshow_width = check_plain(at_get_setting('slideshow_width'));
    $slideshow_css = '.flexible-slideshow,.flexible-slideshow .article-inner,.flexible-slideshow .article-content,.flexslider {max-width: ' .  $slideshow_width . 'px;}';
    drupal_add_css($slideshow_css, array(
      'group' => CSS_DEFAULT,
      'type' => 'inline',
      )
    );
  }

  // Draw stuff
  drupal_add_js($path_to_theme . '/scripts/draw.js');

}

etc.

Jeff Burnz’s picture

There is a small error (but big problems if you leave this), you included the curly brace, which is not needed only the line of code, in your example remove the curly brace that you included directly after the line of code:

  $vars['html_attributes_array']['xmlns:og'][] = 'http://opengraphprotocol.org/schema/'; <-- YOU ONLY NEED THIS LINE
} <-- REMOVE THIS
bcobin’s picture

Thanks, Jeff - made the change!

One more question, though (and I really appreciate your timely and excellent help with all this):

The attribute seems to be declared only for IE - which might be correct, as far as I know. Below is the beginning of the page source, which is the only place the declaration appears. Is that right?

Thanks again here...

<!DOCTYPE html>
<!--[if IEMobile 7]><html class="iem7" lang="en" dir="ltr" xmlns:og="http://opengraphprotocol.org/schema/"><![endif]-->
<!--[if lte IE 6]><html class="lt-ie9 lt-ie8 lt-ie7" lang="en" dir="ltr" xmlns:og="http://opengraphprotocol.org/schema/"><![endif]-->
<!--[if (IE 7)&(!IEMobile)]><html class="lt-ie9 lt-ie8" lang="en" dir="ltr" xmlns:og="http://opengraphprotocol.org/schema/"><![endif]-->
<!--[if IE 8]><html class="lt-ie9" lang="en" dir="ltr" xmlns:og="http://opengraphprotocol.org/schema/"><![endif]-->
<!--[if (gte IE 9)|(gt IEMobile 7)]><!--><html lang="en" dir="ltr" xmlns:og="http://opengraphprotocol.org/schema/" prefix="content: http://purl.org/rss/1.0/modules/content/ dc: http://purl.org/dc/terms/ foaf: http://xmlns.com/foaf/0.1/ og: http://ogp.me/ns# rdfs: http://www.w3.org/2000/01/rdf-schema# sioc: http://rdfs.org/sioc/ns# sioct: http://rdfs.org/sioc/types# skos: http://www.w3.org/2004/02/skos/core# xsd: http://www.w3.org/2001/XMLSchema#"><!--<![endif]-->
<head>

etc. The declaration appears nowhere else. Again - this could be right - just checking... and sorry to be a pain. Thanks much!

Jeff Burnz’s picture

It appears for all, its how the conditional comments trick works.

bcobin’s picture

Thanks, Jeff - you're my hero. Issue closed!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.