how to change the comment link text " Login or register to post comment" to be shorter ,eg " comment"? thanks in advance!

Comments

WorldFallz’s picture

Probably the easiest way is use the http://drupal.org/project/stringoverrides module.

Edward.H’s picture

Hi WoridFallz

thanks,but I tried the Stringoverrides before I posted this topic, it won't work. I think probably because "Login or register to post comment" is not pure string that contains links.

WorldFallz’s picture

It would be really helpful if you would include info about what you've already tried in your posts.

Try this in your template.php file:

function phptemplate_links($links, $attributes = array()) {
  global $user;
  if (!$user->uid && $links['comment_forbidden']) {
    $links['comment_forbidden'] = 'Comment';
  }
  return theme_links($links, $attributes);
}
Edward.H’s picture

thanks WorldFallz,but I got below error

Fatal error: Cannot use string offset as an array in /var/www/teshine/includes/theme.inc on line 555

michelle’s picture

Instead of

$links['comment_forbidden'] = 'Comment';

try

$links['comment_forbidden']['title'] = 'Comment';

That's off the top of my head, not sure if I"m remembering right.

Michelle

Edward.H’s picture

it works!thanks a lot!

bwood’s picture

Stringoverrides.module works - at least current version 6.x-1.8 does. As stated on the project page:

Easily replace anything that's passed through t()

If you look at comment module you can see the placeholders that are passed to t(). So:

Original:

<a href="@login">Login</a> or <a href="@register">register</a> to post comments

Replacement:

<a href="/cas?destination=node%2F71%23comment-form">Login</a> to post comments

This makes the site play nicer with cas.module.

styrbaek’s picture

The above function works like it should.
But i cant figure out how to make the chance on a specific nodetype.

Do anyone have at suggestion??

Jason Dean’s picture

For a specific node type, I tried the following in my template.php:

function phptemplate_links($links, $attributes = array()) {
  global $user;
  if (!$user->uid && $links['comment_forbidden'] && $vars['node']->type == 'my_node_type') {
    $links['comment_forbidden']['title'] = 'My custom text here';
  }
  return theme_links($links, $attributes);
}

But it doesn't work... :(

WorldFallz’s picture

the links template function doesn't have access to the node or the variables array. You'll probably have to use hook_link_alter in a custom module for that.

Jason Dean’s picture

I added a module with this code:

function mymodule_link_alter(&$links, $node) {
  global $user;
  if ($links['comment_forbidden'] && $node->type =="my_node_type" && !$user->uid) {
    $links['comment_forbidden']['title'] = 'my custom message here';
  }
}  

Many thanks!

WorldFallz’s picture

excellent-- thanks for posting back the working code.

halloffame’s picture

How do you get the destination link working? Its logging back you in to the frontpage.

Meditate’s picture

Don't know about others but somehow it solved my problem at least.

j0e’s picture

replace the following:

<a href="@login">Login</a> or <a href="@register">register</a> to post comments

jmagunia’s picture

Had a slightly different string than j0e for Drupal 7 to remove the string altogether:

$conf['locale_custom_strings_en'][''] = array(

'<a href="@login">Log in</a> or <a href="@register">register</a> to post comments' => '',

);

tepelena’s picture

Does anyone know how to change this on Drupal 8? Thanks

vm’s picture

you can try using settings.php in the following sections:

/**
 * String overrides:
 *
 * To override specific strings on your site with or without enabling the Locale
 * module, add an entry to this list. This functionality allows you to change
 * a small number of your site's default English language interface strings.
 *
 * Remove the leading hash signs to enable.
 *
 * The "en" part of the variable name, is dynamic and can be any langcode of
 * any added language. (eg locale_custom_strings_de for german).
 */
# $settings['locale_custom_strings_en'][''] = [
#   'forum'      => 'Discussion board',
#   '@count min' => '@count minutes',
# ];