I've got a custom template page called 'shop', which is found at the URL http://mysite.com/shop/. This page lays out all the posts of post_type 'product' like this:

<div class="product">  
<a name="product-name"></a>
<img src="path/to/image.jpg" />  
<h4>Product name</h4>`  
<p>A description of the product.</p>  

On another page, I've got a link like this:

<a href="/shop#product-name">Buy this product!</a>

I want that link to go to the /shop page, then scroll down to position the page right at the anchor link for this product. But it seems like WordPress' 'pretty permalinks' redirection is getting in the way: as soon as it switches to the /shop#product-name page, the URL gets rewritten to /shop/ and the browser leaves the page scrolled at the top.

My .htaccess file is exactly what WordPress generated: it looks like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Any help in getting these anchor links to work properly would be much appreciated.

(Moderator Note: Title was originally "My permalinks setup doesn't like anchor links to another page.")

  • 1
    Was title change really necessary here? Question is really about anchor link, not messing with permalink setup (which might or might not be required in the end).
    – Rarst
    Oct 4, 2010 at 7:38
  • I agree—in the end, the solution involved changing the anchor links, not the permalinks. (Of course, my original title was no masterpiece.) I've changed it again, to something that I hope works better.
    – Gabe
    Oct 4, 2010 at 13:22

2 Answers 2


Dumb question, but had you tried:

<a href="/shop/#product-name">Buy this product!</a>
  • I think this is the exact solution.
    – sgelob
    Oct 4, 2010 at 7:22

Hi @Gabriel Roth:

Any chance you can just code it like this? (note the trailing slash after /shop):

<a href="/shop/#product-name">Buy this product!</a>

Of course if you must have it without a trailing slash I think this will do what you need although I can't fully test for your use-case, you'll have to try it. You copy this code into a plugin or more easily, your theme's functions.php file:

add_filter('user_trailingslashit', 'no_trailing_slash_on_shop');
function no_trailing_slash_on_shop($url_path) {
  if ($url_path=='/shop/')
    $url_path = '/shop';
  return $url_path;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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