Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Minor: Attachment Pages Broken #875

dominic-p opened this Issue Mar 23, 2012 · 11 comments


None yet
5 participants

dominic-p commented Mar 23, 2012

I just noticed a pretty minor issue, but I wanted to bring it up anyway. When I am looking through the Media Library on the back end, and I click "View" for an image that's attached to a WooCommerce product, I get a 404 error page instead of the attachment page.

www.example.com/shop/product-slug/attachment-slug -> 404 error

I am using a slightly modified permalink structure (/blog/%postname%/), so I'm not sure if this is just me or not, but other non-woocommerce attachment pages seem to be working fine.


mikejolley commented Mar 26, 2012

Tricky one. I'll ask coen to take a look when he starts.


Ramoonus commented Mar 30, 2012

you mean @coenjacobs ?


Mamaduka commented Mar 30, 2012

Can't reproduce, also custom permalink structure doesn't affect custom post type permalinks.


Ramoonus commented Mar 30, 2012

are you using a SEO plugin?

@ghost ghost assigned coenjacobs Mar 30, 2012


mikejolley commented Mar 30, 2012

Reproduce it by setting the 'shop' as your base in category settings.


dominic-p commented Mar 30, 2012

@Ramoonus, nope, no SEO plugin. Like @mikejolley said, I have 'shop' set as the base in my category settings.


coenjacobs commented Apr 2, 2012

Was able to reproduce when in settings also "Prepend product permalinks with product category" is set. If categories aren't used in product/attachment urls, everything works as it should. Will investigate in next couple of days how to make this rewrites (including prepended product category) work properly.


dominic-p commented May 8, 2012

Just wanted to follow up on this. I'm also seeing similar issues when I attempt to prepend the 'shop' base page to my permalinks for other custom post types and taxonomies. For example, I added a simple taxonomy to the product post type that lets me select an item's condition (new, used, etc.). If I set the rewrite slug for my taxonomy to shop/condition, the URLs 404 just like the attachment pages.

I'm not 100% sure this is related, but it kind of feels like it is to me, so I wanted to pass it on.


dominic-p commented Jun 5, 2012

I've been doing a little more checking into this, and I have to say that I'm quite baffled as to what the problem is. I almost feel like it has something to do with the template_loader function.

On all of the pages that I'm seeing 404, that function is returning my index.php instead of attachment.php or single.php which I might expect to be used. Honestly, I could be way off base here though. Has anyone else made any progress on this?


dominic-p commented Jun 5, 2012

Ok, sorry to double post, but I just had a thought, and it looks like the problem isn't with the template_loader function. If you look at the global $wp_query variable for the attachment pages (or any of the other pages I mentioned that are 404ing), you will see that it's parsing the product category and the product slug as the product_cat and then the attachment slug is being parsed as the product. This definitely seems like the problem to me, but I'm not exactly sure how it can be avoided.


dominic-p commented Jun 12, 2012

As an update, I finally sorted the 404s on the custom post types and taxonomies that start with shop issue. Basically, I just adjusted the priority of my register_post_type actions to fire before the WooCommerce init hook fires and everything worked perfectly.

The attachment page issue is another story. From what I can tell, the built in post post type handles this problem with a rewrite rule that looks like this (assuming a permalink structure of blog/%postname%):

[blog/[^/]+/([^/]+)/?$] => index.php?attachment=$1

Could something similar be used for WooCommerce?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment