Site icon Hip-Hop Website Design and Development

Add /amp at the beginning of the URL instead of the end

url structure with this: www.example.com/post-name/amp/

and i want the url to be like this: www.example.com/amp/post-name/

how can i do this in this code?

define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );

add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );

add_filter( 'template_include', 'amp_page_template', 99 );

function amp_page_template( $template ) {

    if( get_query_var( AMP_QUERY_VAR, false ) !== false ) {


        if ( is_single() ) {

            $template = get_template_directory() .  '/amp-single.php';

        } 

    }

    return $template;
}