In WordPress there is defined a simple routing


So when I access /projects/ it loads me Projects page which has specified custom template_projects.php template.

Is it possible to extend routing but only for this template ?

Let's say I want to extend routing to handle project id, so it should be:


But other pages will work with base route.


In your case you need to register custom post type for your projects. You can do it by using register_post_type function:

add_action( 'init', 'wpse8170_register_post_type' );
function wpse8170_register_post_type() {
    register_post_type( 'wpse8170-projects', array(
        'label'   => 'Projects',
        'public'  => true,
        'rewrite' => array( 'slug' => 'project' ),
    ) );

Don't forget to flush rewrite rules.

After you register your custom post type, your projects will have /project/%wpse8170-projects% (%wpse8170-project% will be replaced by project slug) permalink structure and you will be able to use single-wpse8170-projects.php template for your projects.

| improve this answer | |
  • Explain me please, why there is wpse8170 keyword ? – hsz Aug 9 '13 at 10:39
  • I have already did it, but I want to 'consume' projects in specified Page. So I have to fetch project in /projects/project-slug but projects post has to be available too. – hsz Aug 9 '13 at 10:41
  • @hsz wpse8170 is unique prefix which prevents collision issues. You can pick up your own unique prefix and use it in your development. – Eugene Manuilov Aug 9 '13 at 11:35
  • @hsz use archive-wpse8170-projects.php template to render archive page for project posts. In this template, fetch projects post/page and render it's content instead of rendering projects list. – Eugene Manuilov Aug 9 '13 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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