I'm making a wordpress child theme as an app. I would like to make a rewrite of an URL in the theme, since it's sometimes more seo friendly.
If someone enters for example www.domain.com/show-new-cars/
I would like the server to load www.domain.com/index.php?loadcars=1
I tried to put this in the child theme folders functions.php without any results.
add_action( 'init', 'wpse7379_init' );
function wpse7379_init()
{
add_rewrite_rule('show-new-cars/',
'index.php?loadcars=1',
'top');
}
$wp_rewrite->flush_rules(); does the trick.
This is an update due to not using flush every time the page loads, since it can increase server load allot.
//When activated trough admin
if ( is_admin() && isset($_GET['activated'] ) && $pagenow == 'themes.php' ) {
add_action( 'init', 'wpse7379_init' );
function wpse7379_init()
{
add_rewrite_rule('show-new-cars/',
'index.php?loadcars=1',
'top');
}
$wp_rewrite->flush_rules();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.