Custom permalink variable on single post

Question

I’m trying rewrite url for permalink on single post
my permalink: /%postname%/
My single form: http://example.com/abc-def/?chapter=1
adc-def mean: %postname%

i want permalink is: http://example.com/abc-def/chapter/1
But it is not possible.
this is my code:

add_action( 'init', 'myblog_rewrites_init' );
function myblog_rewrites_init(){
    add_rewrite_rule(
        '([^/]+)/([0-9]+)/?$',
        'index.php?name=$matches[1]&chapter=$matches[2]',
        'top' );
}

add_filter( 'query_vars', 'myblog_rewrite' );
function myblog_rewrite( $query_vars ){
    $query_vars[] = 'chapter';
    return $query_vars;
}

Please help me! Thanks every body!

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/custom-permalink-variable-on-single-post/">

Custom permalink variable on single post</a>
0
, quyet 1 month 0 Answers 48 views 0

Leave an answer