Support » Developing with WordPress » custom rewrite rule on homepage no slug

  • Hello, I’m looking to add a custom rewrite rule in homepage.
    Now I send the variable using this code

    
    function add_query_vars($customVars) {
        $customVars[] = "myvariable"; 
        return $customVars;
    }
    add_filter('query_vars', 'add_query_vars');
    
    function my_rewrite_tag_rule() {
    add_rewrite_rule( '^mytype/([^/]*)/?', 'index.php?page_id=pagenumber&myvariable=$matches[1]','top' );
    }
    add_action('init', 'my_rewrite_tag_rule', 10, 0);
    

    and I got this url format
    http://mywpsite/mytype/myvariable/

    It’s possible to get a url like this ?
    http://mywpsite/myvariable/

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You could, but then normal post permalinks would not work unless you also require a post type slug for regular posts. Otherwise WP wouldn’t know to query for mytype or for post post types. The permalinks can only manage one default post type, everything else needs a alug.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.