Uppercase to Lowercase in URL

This is NOT mod_rewrite rule, it’s WordPress rewrite rule and it proposes to parse variables from URL to wp_query (most of the time). You can apply your logic during parse_query filter hook., something like this. add_filter( ‘parse_query’, function( WP_Query $wp_query ) : WP_Query { foreach ( [ ‘symbol’, ‘exchange’ ] as $key ) { if … Read more

Have two different URLs show the homepage

WordPress will always try to redirect to the canonical URL to prevent duplicate content, so you’ll have to disable that mechanism to get another URL to display that page. First, your rewrite rule: add_rewrite_rule(‘^page1’, ‘index.php?pagename=your-page-name’, ‘top’); Then filter redirect_canonical to return false if the requested URL is your 2nd home URL: function my_redir_check( $redirect_url, $requested_url … Read more

Associate the “add_rewrite_endpoint” and “$_GET”

Query parameters added using add_rewrite_endpoint() are available using get_query_var(). So if you register /en/ as an endpoint: function wpse_318560_en_endpoint(){ add_rewrite_endpoint(‘en’, EP_ALL); } add_action(‘init’, ‘wpse_318560_en_endpoint’ ); And don’t flush rewrite rules on init. Rewrite rules only need to be flushed once. See this note in the developer docs for a way to properly flush rewrite rules … Read more

how to add extra GET parameters to post to url with add_rewrite_rule?

You want to use the add_rewrite_endpoint since what you are concerned with is at the end of the URL. function wpseo331941_reader_endpoint() { add_rewrite_endpoint(‘readers’, EP_PERMALINK | EP_PAGES); } add_action(‘init’, ‘wpseo331941_reader_endpoint’, 10, 0); //When you want to check if the ‘readers’ is being used if ( false !== get_query_var(‘readers’, false) ){ //…. } Note that the false … Read more

Special domain for a page

There is a plugin that does exactly this: https://wordpress.org/plugins/multiple-domain-mapping-on-single-site Anyway, it would be nicer to have things under control with an understandable few lines of script, so I’m still open to answers

Custom url for a plugin page add_rewrite_rule WordPress

After a long search finally i found a working solution. I am posting here in case someone face the similar issue, it would be helpful. Here is my working code: add_action(‘template_redirect’, array($this, ‘zip_template’)); add_filter( ‘rewrite_rules_array’, array($this, ‘zip_rule’) ); add_filter( ‘query_vars’, array( $this, ‘zip_query_vars’ ) ); add_action( ‘wp_loaded’, array( $this, ‘flush_rules’ ) ); /** * Rewrite … Read more

How much control do we have over CPT rewrite slugs? Can I create a “root” page for my CPT with out the page path, and then have paths for other pages?

The way I see it, you could do: // Via the init hook, do all these: register_post_type( ‘library-books’, [ ‘public’ => true, ‘label’ => ‘Library Books’, ‘rewrite’ => [ ‘with_front’ => false, ‘slug’ => ‘library/books’ ], ‘has_archive’ => ‘library/books’, // other args here ] ); register_post_type( ‘library’, [ ‘public’ => true, ‘label’ => ‘Libraries’, ‘rewrite’ … Read more

What’s the Simplest Way to Override/Rewrite the %category% Permalink Structure Tag?

Yes, the post_link_category hook is indeed what you would use to filter the %category% replacement value in the permalink. And here’s an example with prominent_cat being the meta key and the value being the category name (e.g. Pizza Hut), where I’m using get_term_by() to get the category object/data: add_filter( ‘post_link_category’, ‘my_post_link_category’, 10, 3 ); function … Read more