Nesting if statements to echo only one string based on what tag was filtered?

is_tag() returns whether the query is for an existing tag archive page. This isn’t what you want to use. Instead, use get_query_var(). get_query_var( ‘tag’ ) will look at the tag query variable in the URL. For instance, if your URL is https://example.com/?tag=this&other=that then using: get_query_var( ‘tag’ ) will return this get_query_var( ‘other’ ) with return … Read more

Changing WordPress Address URL disaster

Fixed by adding a htaccess file to the root directory with this information: <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?example.com$ RewriteCond %{REQUEST_URI} !^/my_subdir/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /my_subdir/$1 RewriteCond %{HTTP_HOST} ^(www.)?example.com$ RewriteRule ^(/)?$ my_subdir/index.php [L] </IfModule> The main issues was WordPress being installed in a subdirectory, so the root URL was … Read more

WordPress redirects non-existing url to existing ones – how to disable

This question is a duplicate of Disable ONLY URL auto complete, not the whole canonical URL system Try this filter function remove_redirect_guess_404_permalink( $redirect_url ) { if ( is_404() ) return false; return $redirect_url; } add_filter( ‘redirect_canonical’, ‘remove_redirect_guess_404_permalink’ ); Or this plugin: https://wordpress.org/plugins/disable-url-autocorrect-guessing/

How to catch Rewrite rules then display a specific post?

It appear, like @milo also said, that the correct way to doing this is by using the “parse_request” action that stand before the “pre_get_posts” action (see https://codex.wordpress.org/Plugin_API/Action_Reference). The complete solution I came with : add_action(‘init’, function () { $refs_slug = getCustomRefTermsSlug(); // this will return an array of all the terms slug existing in the … Read more

Preserve Domain Alias

You need to set the canonical hostname (ie. with www) in the WordPress dashboard… Under Settings > General and set the appropriate “WordPress Address (URL)” and “Site Address (URL)” properties. Alternatively, these values can be hardcoded in wp_config.php by defining the WP_HOME and WP_SITEURL constants respectively. Reference: https://codex.wordpress.org/Changing_The_Site_URL SSLOptions +StrictRequire SSLRequireSSL SSLRequire %{HTTP_HOST} eq “example.com” … Read more

How do I redirect to a non-www version and make it the default URL?

This process can be broken into 2 steps: Using .htaccess for Redirection First, you should redirect any traffic from www to non-www version of your website, by using a simple rewrite rule: RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] This … Read more

Static variable and add_rewrite_rule?

You can’t add arbitrary query variables to the rewrite rules, there’s a whitelist of allowed variables. To add a query variable, use query_vars filter, e.g. this filter adds my-api as a valid query variable: function wpd_query_vars( $query_vars ){ $query_vars[] = ‘my-api’; return $query_vars; } add_filter( ‘query_vars’, ‘wpd_query_vars’ ); But that just gets you the query … Read more

optimize wordpress rewrite rule regex

With all part optional with ?, you obtain one rule to rule them all : add_rewrite_rule( ‘^cities/(.*)/(browse)?/?(.*)?/?(.*)?/?(.*)?/?(.*)?/?’, ‘index.php?city_name=$matches[1]&cat_name[]=$matches[3]&cat_name[]=$matches[4]&cat_name[]=$matches[5]’, ‘top’ ); but the [] cannot work with the WordPress logic then you need to define the rewrite tag with a number. try that : add_rewrite_tag(“%cat_name.%”, “([^&]+)”); add_rewrite_rule( ‘^cities/([^/]*)/(browse)?/?([^/]*)?/?(^/)?/?([^/]*)?/?([^/]*)?/?’, ‘index.php?city_name=$matches[1]&cat_name1=$matches[3]&cat_name2=$matches[4]&cat_name3=$matches[5]’, ‘top’ );