Set a page as parent of a custom post type.

I am currently redesigning my homepage and I want to build an image gallery with a permalink structure like the one on css-tricks (ex: **homepage/gallery/postname**).
I created a Custom Post Type in WordPress, to post each uploaded image on a seperate page. And I changed the rewrite slug of that post type, to get the permalinks right. But my Yoast Breadcrumbs still display something like: **homepage/postname** instead of: **homepage/gallery/postname**. After a lot of googling I found out, that I need to actually set the gallery page as a parent for the custom post type. WordPress doesn’t let you do that, but I found a [snippet](http://www.gravitationalfx.com/how-to-set-a-page-as-the-parent-of-a-wordpress-custom-post-type/), where one can specify a parent to the custom post type in wp’s admin area.

But isn’t there a easier solution to that problem? I know the post_id of my gallery page. And I don’t want to use any other parent page for my images, ever. So I don’t need any dropdown menus or text inputs. I just want that one custom post type to always have the gallery page as a parent.

I tried to fiddle around with the code, but I’m just too bad at PHP, to get it to work. So any help would be appreciated.

**EDIT**: After another 4 hours of tinkering… something starts to boggle my mind. Am I going down the right way, implementing the gallery like this or should I use another approach? I’m asking that, because after giving up on my initial problem and working on the gallery home page, I noticed, that it uses the **archive-custom post type.php** template and won’t accept any other template. That’s not the real problem though… I could just copy my markup from gallery.php to the archive-whatever.php, but Yoasts Breadcrumbs won’t label it as gallery but instead as the name of my custom post type… which is a little bit annoying. So… Am I doing it wrong?

@AlenAbdula thank you very much for going through so much trouble for my problem.

One thing keeps me wondering, though. Is this problem really that exotic? I see hundreds of sites on the web with that exact url structure and working breadcrumbs… someone must have come across that problem at least once.

How do you build your image galleries? Does everyone use a plugin or the WP Gallery shortcode? Please enlighten me ;)

Tips

What now? I have some ideas for you.

Go explore CodePen!

As a front end designer and developer, you should have an account on CodePen so you can save your snippets, present your ideas, and engage with other front end folk. I'd encourage you to go PRO as well, to unlock the full power of CodePen.

Get the newsletter!

You should sign up for the CSS-Tricks newsletter. It's a clean copy of all the blog posts each week, combined together, right to your inbox. If email isn't your thing, there is an RSS feed, iTunes, and lots of other ways to subscribe.

Listen to ShopTalk!

Subscribe to The Lodge!

The Lodge is a members-only, ad-free video learning area here on CSS-Tricks. Just like the free screencasts, but organized into four large complete series. Membership is also the #1 best way to support CSS-Tricks.

We can do the real footer now.

Site Links

Colophon

CSS-Tricks* is created, written by, and maintained by Chris Coyier. It is built on WordPress, hosted by Media Temple, and the assets are served by MaxCDN. The fonts are Source Sans and Source Code Pro. It is made possible by viewers like you who subscribe to The Lodge and through advertising for products and services I like.