Adding two rewrite rules

1. Change new_category taxonomy’s rewrite rule while registering: ‘rewrite’ => [‘hierarchical’ => false, ‘with_front’ => false, ‘slug’ => ‘news’] Make sure rewrite rule of news post type is default or: ‘rewrite’ => [‘slug’ => false, ‘with_front’ => false] 2. Add rewrite rules for new_category: add_action(‘init’, function() { add_rewrite_rule(‘^news/([^/]+)/?$’, ‘index.php?new_category=$matches[1]&post_type=news’, ‘top’); }); 3. Filter news post … Read more

Rewriting a page with a custom parameter

To fix this issue, we had to add the “query variables” into the functions.php of our theme to add them to the public variables. function add_query_vars_filter($vars){ $vars[] = “subject”; $vars[] = “param”; return $vars; } add_filter(‘query_vars’, ‘add_query_vars_filter’); This allowed us to retrieve the variables’ value this way. $subject = get_query_var(‘subject’, false);

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

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