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

    It’s possible to get a url like this ?

Viewing 1 replies (of 1 total)
  • Moderator 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)
  • The topic ‘custom rewrite rule on homepage no slug’ is closed to new replies.