I created a shortcode by add_shortcode. where the shortcode placed in a wordpress page to display dynamic content. The dynamic content is based on the URL value.


If URL is wordpress/sample-page/?user=john in my shortcode content I get the url value by $_GET['user']

Now I would like to rewrite the url like wordpress/sample-page/john. And want to get the URL values in shortcode. Is this possible in wordpress? if so Please guide me.


The simplest and quickest solution would be to use the add_rewrite_endpoint function.

<?php add_rewrite_endpoint( $name, $places ); ?>

So in your case it would be something like this:

add_rewrite_endpoint( 'user', EP_PERMALINK | EP_PAGES );

An user URL would look like this:


To access the variable:

$user = get_query_var( 'user', false );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.