Is it possible to change the URL of custom post types to hide the post type slug?

You need to use option 'rewrite' in your custom post type registration.

E.g.
'rewrite' => array('slug' => 'products'),

From the codex

When you namespace a URL and still want to use a “clean” URL
structure, you need to add the “rewrite” element to the array. For
example, assuming the “ACME Widgets” example from above:

add_action( 'init', 'create_post_type' );
function create_post_type() {
  register_post_type( 'acme_product',
      array(
          'labels' => array(
              'name' => __( 'Products' ),
              'singular_name' => __( 'Product' )
          ),
          'public' => true,
          'has_archive' => true,
          'rewrite' => array('slug' => 'products')
      )
  );
}

The above will result in a URL like
http:/example.com/products/%product_name% (see description of
%product_name% above.) Note that we used a plural form here which is a
format that some people prefer because it implies a more logical URL
for a page that embeds a list of products, i.e.
http:/example.com/products/.

Also note using a generic name like “products” here can potentially
conflict with other plugins or themes that use the same name but most
people would dislike longer and more obscure URLs like
http:/example.com/acme_products/foobrozinator and resolving the URL
conflict between two plugins is easier simply because the URL
structure is not stored persistently in each post record in the
database in the same way custom post type names are stored.

Leave a Comment