• Hi, i want to create a page slug for example. https://www.mysite.com/users
    But i don’t want to create that page called ‘users’ in wordpress admin panel.
    I just need this slug to be registered with wordpress as page slug and when someone will request this page i will redirect them to my custom template.

    I need to add slug to wordpress, something like below code.

    add_action( 'init', 'bbf_rewrite_init' );
    function bbf_rewrite_init() {
      add_rewrite_rule( 'users/?$', 'index.php?pagename=users', 'top' );
    }

    And then use the condition if_page(“users”) and redirect them to my custom template, something like below code.

    add_filter( 'template_include', 'bbf_template_redirect', 99 );
    function bbf_template_redirect( $template ) {
      global $wp_query;
      if ($wp_query->query_vars["name"] == "users"){
        $template = get_template_directory(). 'page-users.php';
      }
      return $template;
    }

    Can anyone help me please? I need these kind of knowledge for my new wordpress plugin.
    Thanks

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Create a page slug without creating a page in wp-admin’ is closed to new replies.