Using a Rewrite URL in a Plugin to Load a New Page in the Template

add_rewrite_rule( $regex, $redirect, $after ); Rewrite rules to scripts other than index.php The $redirect argument works slightly differently when redirecting to a custom PHP script because WordPress delegates these redirects to .htaccess instead of processing them itself. For this reason, querystring variables should be written like $1 instead of $matches[1]. Personally, I would use a … Read more

Adding URL prefix for foreign language support

Are you sure you have correct regex? Also you shouldn’t use flush_rewrite_rules() on init hook. Better to just go and re-save permalinks options in admin, so you won’t flush rules every time. Try to change regex to all chars, otherwise it looks good. add_rewrite_rule (‘^([^/]*)/?’, ‘index.php?lang=$matches[1]’, ‘top’); UPDATE: and then you need to add parameter … Read more

Custom Post Type Category URL

Option 1: Enable the post type archives and use a post type archive template. Enable the archives; e.g. when registering the post type using register_post_type(): register_post_type( ‘shop’, [ ‘has_archive’ => ‘shop’, // the archives are accessible at example.com/shop // … ] ); Then create a custom archive template just for that post type; i.e. archive-shop.php. … Read more

add_feed rewrite overwriting standard permalinks

If you don’t want to use add_feed(), then you can use add_rewrite_rule(): add_action( ‘init’, function () { add_rewrite_rule( ‘^feed/(schedule|calendar)/?$’, ‘index.php?feed=$matches[1]’, ‘top’ ); } ); add_action( ‘do_feed_schedule’, function () { header( ‘Content-Type: text/plain’ ); // dummy type just for testing echo ‘Yay, it works!’; } ); But regarding the original question about add_feed().. Why would WordPress … Read more

Show category name in the post URL only for specific categories

The easiest way would be to create a custom post type with an archive. <?php register_post_type(‘resource’, array( // Enable Core Categories and Tags ‘taxonomies’ => array(‘category’, ‘post_tag’), // Enable in REST API so it works with the Block Editor ‘show_in_rest’ => true, ‘label’ => ‘Resources’, ‘public’ => true, ‘supports’ => array(‘title’, ‘editor’, ‘excerpt’, ‘thumbnail’, ‘revisions’), … Read more