Title: Custom permalink with only post name
Last modified: December 6, 2016

---

# Custom permalink with only post name

 *  Resolved [tgeddy](https://wordpress.org/support/users/tgeddy/)
 * (@tgeddy)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-permalink-with-only-post-name/)
 * I have custom fields called “games” and I want their permalinks to be **example.
   com/game-name**.
 * If I change the WordPress permalink setting to post name, I get **example.com/
   games/game-name**. If I change the custom rewrite slug setting in cpt ui to _%
   postname%_, I get **example.com/game-name/game-name**. How can I get it to be**
   example.com/game-name**? Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [9 years, 5 months ago](https://wordpress.org/support/topic/custom-permalink-with-only-post-name/#post-8520905)
 * That’s a topic that CPTUI doesn’t attempt to cover, as it gets into the rewrite
   rules API and customizing permalinks at a higher level. One thing to keep in 
   mind is that the “game-name” first part of the URL is helping with the querying,
   telling WordPress to only look at the “game-name” post type slug, instead of 
   having to look at ALL rows in the posts table.
 * I know there are tutorials out there for the topic, but it’s simply not something
   our UI will cover.
 *  [freehack](https://wordpress.org/support/users/freehack/)
 * (@freehack)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/custom-permalink-with-only-post-name/#post-8578228)
 *     ```
       function remove_cpt_slug( $post_link, $post, $leavename ) {
   
           if ( 'games' != $post->post_type || 'publish' != $post->post_status ) {
               return $post_link;
           }
   
           $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
   
           return $post_link;
       }
       add_filter( 'post_type_link', 'remove_cpt_slug', 10, 3 );
   
       function gparse_request_trick( $query ) {
   
           // Only noop the main query
           if ( ! $query->is_main_query() )
               return;
   
           // Only noop our very specific rewrite rule match
           if ( 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
               return;
           }
   
           // 'name' will be set if post permalinks are just post_name, otherwise the page rule will match
           if ( ! empty( $query->query['name'] ) ) {
               $query->set( 'post_type', array( 'post', 'page', 'games' ) );
           }
       }
       add_action( 'pre_get_posts', 'parse_request_trick' );
       ```
   
    -  This reply was modified 9 years, 4 months ago by [freehack](https://wordpress.org/support/users/freehack/).
    -  This reply was modified 9 years, 4 months ago by [freehack](https://wordpress.org/support/users/freehack/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom permalink with only post name’ is closed to new replies.

 * ![](https://ps.w.org/custom-post-type-ui/assets/icon-256x256.png?rev=2744389)
 * [Custom Post Type UI](https://wordpress.org/plugins/custom-post-type-ui/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-post-type-ui/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-post-type-ui/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-post-type-ui/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-post-type-ui/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-post-type-ui/reviews/)

## Tags

 * [permalink](https://wordpress.org/support/topic-tag/permalink/)
 * [slug](https://wordpress.org/support/topic-tag/slug/)

 * 2 replies
 * 3 participants
 * Last reply from: [freehack](https://wordpress.org/support/users/freehack/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/custom-permalink-with-only-post-name/#post-8578228)
 * Status: resolved