How can I create custom URL routes?

Add this to your theme’s functions.php, or put it in a plugin. add_action( ‘init’, ‘wpse26388_rewrites_init’ ); function wpse26388_rewrites_init(){ add_rewrite_rule( ‘properties/([0-9]+)/?$’, ‘index.php?pagename=properties&property_id=$matches[1]’, ‘top’ ); } add_filter( ‘query_vars’, ‘wpse26388_query_vars’ ); function wpse26388_query_vars( $query_vars ){ $query_vars[] = ‘property_id’; return $query_vars; } This adds a rewrite rule which directs requests to /properties/ with any combination of numbers following to … Read more

add_rewrite_rule on default post type

This would be bad practice, since WordPress already has a functionality to do this built in. Rewriting the built in functionality is never a good idea. To achieve this the best way is to use Taxonomies. Lets say you create two categories: Foo Bar Now select the categories for the post in question and setup … Read more

add_rewrite_rule() not stored (I think)

It’s not showing up because internal rewrites must point to index.php. This isn’t your theme’s index.php file, it’s the main root WordPress bootstrap file. This is how WP detects what should be an internal rule (parsed in PHP) and an external rule (added to htaccess). The other issue you will have is that page_name isn’t … 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

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

WooCommerce – Conditional for page created by rewrite_rule

In WordPress, the request path, e.g. path/to/something as in example.com/path/to/something?query=string&if=any, is saved in WP::$request which is accessible via the global $wp variable, so in your case, you can do so to check if the page is /dashboard/products: global $wp; // Note: No trailing slashes. $is_my_page = ( ‘dashboard/products’ === $wp->request ); // Or without the … Read more

Route subpage to Custom Post Type

I usually struggle with this, however this time I managed it relatively easy. Main reference for this answer is here: https://codex.wordpress.org/Rewrite_API/add_rewrite_rule I’d like to use anything in the below as discipline. /artists/djave_co/anything First of all, I added a “rewrite tag” function custom_rewrite_tag() { add_rewrite_tag(‘%discipline%’, ‘([^&]+)’); } add_action(‘init’, ‘custom_rewrite_tag’, 10, 0); Next, I did print_r($wp_query->query_vars) on … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)