Skip to content

Creating routes for custom WordPress post types…

When you’re creating a somewhat more complex WordPress website, you might want to create some custom routes for any custom post types that you create. Whether this is to maximise SEO or just make the URLs a bit prettier, it’s pretty simple to do. The function below added to your theme function.php file illustrates the general idea…


function sweetapple_rewrites_init(){

    add_rewrite_rule(
        'houses/([^/]*)/([^/]*)/?',
        'index.php?pagename=houses&house_search_type=$matches[1]&house_search_query=$matches[2]',
        'top');
    //
    add_rewrite_tag('%house_search_type%','([^&]+)');
    add_rewrite_tag('%house_search_query%','([^&]+)');
}
add_action( 'init', 'sweetapple_rewrites_init' );

Looking for an experienced freelance WordPress developer to convert your designs into a custom theme? Need help customising an existing theme, theme framework, or creating a WordPress child-theme? Please give us a call on 01380 830224.

This entry was posted in Web Development and tagged , , . Bookmark the permalink.

Comments

Sorry, comments are closed on this page.