I've noticed that the article tag contains a header tag that is only displayed when the view not a page. I'm guessing this is for teaser views? Or perhaps more blog style pages where multiple nodes are rendered on 1 page...

My problem is that when in page mode showing the single node (node/%) then shouldn't the article still output the header ? I know there is an H1 tag on the page and the article is article > header > h2:title.

Is this a semantic issue or it doesn't really matter? My use case is placing some node meta content before the title which means in my case disabling the page title.

Comments

johnalbin’s picture

No, the proper way is to put the title inside the <article> tag, but Drupal 7 puts the page title in the page.tpl while the node content remains in node.tpl.

There's no clean way to do this in D7. And there's no fix for this in D8 either. :-\

danny englander’s picture

I've been pondering over this issue on and off for a while now, it's been nagging me in the back of my mind. I noticed that sites that have an <h1> tag within the <article> tag display better for example when you copy and paste a node URL into a Linkedin Status. I tested this out with lots of different sites and in every case when the <h1> appears before the opening <article> tag, the staus was not picked up too well.

I tested out some code within a Zen subtheme I am developing and this is what I did:

  1. Create a page preprocess function to test if the page is a node or not.
    function mycustomzen_preprocess_page(&$vars) {
    // Test if a page is a node and set a variable to use for the h1 in page.tpl.php.
      $vars['is_node'] = false;
      if (isset($vars['node'])) {
        $vars['is_node'] = true;
      }
    }
    // of course as always get rid of the closing php tag below
    
  2. Now in page.tpl.php add the new variable as an if statement to render the <h1> anywhere it's not a node:
      <?php if (!$is_node): ?>
          <?php print render($title_prefix); ?>
          <?php if ($title): ?>
            <h1 class="page--title title" id="page-title"><?php print $title; ?></h1>
          <?php endif; ?>
          <?php print render($title_suffix); ?>
          <?php endif; ?>
  3. Now in node.tpl.php, add an 'else' and provide for an <h1>tag to the existing code that comes after the <article> tag
    <?php if ($title_prefix || $title_suffix || $display_submitted || $unpublished || !$page && $title): ?>
        <header>
          <?php print render($title_prefix); ?>
          <?php if (!$page && $title): ?>
            <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>
          <!-- new code here-->
    <?php else: ?>
            <?php if ($title): ?><h1 class="page-title"><?php print $title; ?></h1><?php endif; ?>
          <?php endif; ?>
          <?php print render($title_suffix); ?>

I tested this with a variety of pages and views and in each case the page title rendered only once and now within nodes, it's just after the <article> tag. I suppose one could argue that this has better SEO as well as semantic value. If anyone is interested, I could roll it into a patch but I am not really sure if what I am doing is correct or using good logic. My guess is that it needs a lot more testing and refinement and I am not even sure if my preprocess function is the best one that could be used. I'd be interested in hearing what the downsides of this are.

danny englander’s picture

After more research and experimentation, this may not be as an important issue as I thought. I kind of went down this road but in reality, what I was probably looking for was better Open Graph Meta data for content sharing so I probably need: http://drupal.org/project/opengraph_meta.

johnalbin’s picture

Status: Active » Closed (won't fix)

Marking this as "can't fix". :-p Good luck!