0

Currently when a node or comment is submitted it gets a Submitted text saying "Submitted by user on Wed, 04/01/2015 - 18:07"

The mark-up for this is:

<span>Submitted by *user* on <time pubdate="pubdate" datetime="2015-04-01T18:07:34+0000">Wed, 04/01/2015 - 18:07</time></span>

What I need to do is remove the "pubdate" attribute from the tag because the it is failing on W3C validation.

I have tried to add the following code in my template.php file but had no luck

function ThemeName_preprocess_node(&$variables) {
    $attributes['datetime'] = '<time'.drupal_attributes($attributes) .'>'.$variables['date'] . '</time>';
}

How can I remove the "pubdate" attribute in the Submitted by tag?

  • In your ThemeName_preprocess_node you need to set some value into $variables otherwise no changes will make it to your template. It's most likely theme dependent what variable you need to set, but you possibly want to override the current value of $variables['date']. Can you post the relevant part of your theme's node.tpl.php? – dblue Apr 3 '15 at 19:51
  • Hi dblue, thanks for the reply. The node.tpl.php for the submitted line is: <?php print $submitted; ?> and then this prints the following in html: <span>Submitted by user on <time pubdate="pubdate" datetime="2015-04-01T18:07:34+0000">Wed, 04/01/2015 - 18:07</time></span> – harnamc Apr 3 '15 at 20:44
0

So `$variables['submitted'] is the one you want to override in your theme's preprocess_node function. Try this as a starting point:

function ThemeName_preprocess_node(&$variables) {
  $variables['submitted'] = t('Submitted by !username', array('!username' => $variables['name']));
}

Which will replace the $submitted variable with "Submitted by username" (where the username will be linked to the user's profile page).

  • The $variable was "$variable['pubdate']", so what I did was theme that in my template.php like this: $variables['pubdate'] = '<time datetime="' . format_date($variables['node']->created, 'custom', 'c') . '">' . $variables['date'] . '</time>'; And it worked. Thanks for your help dblue. Pointed me in the right direction – harnamc Apr 4 '15 at 0:14
0

Need to hook into "preprocess_node" to access the $submitted variable like so:

function THEME-NAME_preprocess_node(&$variables, $hook) {

$variables['pubdate'] = '<time datetime="' . format_date($variables['node']->created, 'custom', 'c') . '">' . $variables['date'] . '</time>';

$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' =>$variables['name'], '!datetime' => $variables['pubdate']));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.