Last active
September 20, 2022 13:52
-
-
Save agilelogix/2d32ccd091c570a1d28fd750f47b49f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Steps to create detail page with SEO friendly URLs. | |
1- Copy the code into functions.php (make sure to replace 1970 with the correct page id of your store detail page) | |
// Pretty URL for the Store Locator | |
add_action( 'init', function() { | |
add_rewrite_rule('^stores/?([^/]*)/?','index.php?page_id=1970&sl-store=$matches[1]','top'); | |
}); | |
// Whitelist the Variable | |
add_filter( 'query_vars', function( $query_vars ) { | |
$query_vars[] = 'sl-store'; | |
return $query_vars; | |
}); | |
2- Add Slug in the URL of the listing | |
<a class="btn btn-block btn-asl" href="/stores/{{:slug}}/"><?php echo __( 'Details','asl_locator') ?></a> | |
3- Click Save Changes in Settings > Permalink Settings. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment