Inside my plugin, I have a page template that I would like it to follow a specific structure.

I would like the template to always use the /%postname%/ permalink structure regardless of what the default permalink structure is set to.

So if someone's structure is set to domain.com/p=123 it will load domain.com/page-name if this template is selected.

1 Answer 1


There are different filters available to create the custom permalinks for the posts, custom posts or pages:

Here is the sample code based on your query:

public function custom_permalink_for_page_template( $url, $post ) {

      if ( is_page() && is_admin() && is_page_template( 'custom_page_template' ) {

         return str_replace( get_site_url(), untrailingslashit( get_site_url() ) . "/custom-permalink-structure", $url );

      } else {
        return $url;

You can also validate the permalink structure settings in the if condition

get_option( 'permalink_structure' )

  • None of this will work if the user has their permalink structure set to Plain. Jul 6, 2018 at 7:53
  • Maybe I wasn't very clear. I'm wanting to know if I can set a template to use a specific permalink structure, like post name (domain.com/sample-post) even if the default permalink structure is set to the plain structure (domain.com/?p=123) Jul 12, 2018 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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