How to hook into core's "log in to comment" link I'm running Advanced Forums on D7, and when an anonymous user views a forum post (lets say nid 101) there is link under the post that says "Log in or register to post comments". 

The problem is it is supposed to point to 'user/login?destination=node/101#comment-form' but the url encoding causes it to become 'user/login?destination=node/101%23comment-form'

I looked inside core's comment module, under function theme_comment_post_forbidden  line 2387 says:

$destination = array('destination' =&gt; "node/$node-&gt;nid#comment-form");
return t('&lt;a href="@login"&gt;Log in&lt;/a&gt; or &lt;a href="@register"&gt;register&lt;/a&gt; to post comments', array('@login' =&gt; url('user/login', array('query' =&gt; $destination)), '@register' =&gt; url('user/register', array('query' =&gt; $destination))));


but I think it should make the #comment-form a url fragment:

$destination = array('destination' =&gt; "node/$node-&gt;nid");
$fragment = 'comment-form';
return t('&lt;a href="@login"&gt;Log in&lt;/a&gt; or &lt;a href="@register"&gt;register&lt;/a&gt; to post comments', array('@login' =&gt; url('user/login', array('query' =&gt; $destination, 'fragment' =&gt; $fragment)), '@register' =&gt; url('user/register', array('query' =&gt; $destination, 'fragment' =&gt; $fragment))));


How I can create a hook to this and change the link?
I found the solution with the help of this SE post. Using MYMODULE_node_view_alter(&amp;$build) and MYMODULE_comment_view_alter(&amp;$build) in my custom module, I was able to change the values using: 

$build['links']['comment']['#links']['comment_forbidden'] = str_replace('%23','#', $build['links']['comment']['#links']['comment_forbidden']);