Permalink Structure CPT With Custom Taxonomy Fails

Setting has_archive to true causes WordPress to generate a rewrite rule for the archive using the rewrite slug, which is not what you want in your case. Instead, explicitly specify the archive slug as a string and the correct rules will be generated: $args = array( ‘has_archive’ => ‘courses’, ‘rewrite’ => array(‘slug’ => ‘courses/%course-type%’,’with_front’ => … Read more

How to use rewrite rule or rewrite endpoint to switch languages?

You cannot do this by just adding a rewrite rule, you need to change every recorded rules. Here is a simple way to do this: function my_rewrite_rules($rules) { $new_rules = array(); $new_rules[‘(?:de|en)/?$’] = ‘index.php’; foreach ($rules as $key => $val) { $key = ‘(?:de|en)/?’ . $key; $new_rules[$key] = $val; } return $new_rules; } add_filter(‘rewrite_rules_array’, ‘my_rewrite_rules’, … Read more

How to Add a Rewrite Rule for Only One Page?

Asumption: You use Apache as your web server. If you already know the page slugs and they won’t change, just add them to your .htaccess file. It’ll be much faster and less complicated. Paste the following Redirect lines at the top of your .htaccess file. Redirect 301 /pagetitle/ /service/pagetitle/ Redirect 301 /pagetitle2/ /another-dir/pagetitle2/ # BEGIN … Read more

How to display posts in hyperlink with nested slugs?

This can be achieved by adding rewrite rules. First, add the query vars that will store the custom values in our rules: function wpd_family_query_var( $query_vars ) { $query_vars[] = ‘wpd_family’; $query_vars[] = ‘wpd_members’; return $query_vars; } add_filter( ‘query_vars’, ‘wpd_family_query_var’ ); Next, add the rules to capture both displaypage/family/ and displaypage/family/members/ requests: function wpd_add_family_rewrite_rules() { add_rewrite_rule( … Read more

Custom page slug without creating a WP page

You’re close, the query var for passing page slug is pagename: add_filter(‘query_vars’, ‘add_account_edit_var’, 0, 1); function add_account_edit_var($vars){ $vars[] = ‘account-edit’; return $vars; } add_action( ‘init’, ‘add_account_edit_rule’ ); function add_account_edit_rule() { add_rewrite_rule( ‘^my-account/([^/]*)/?’, ‘index.php?pagename=my-account&account-edit’, ‘top’ ); } To capture the value in your rule, you need to pass the value in $matches[1]: add_rewrite_rule( ‘^my-account/([^/]*)/?’, ‘index.php?pagename=my-account&account-edit=$matches[1]’, ‘top’ … Read more

Create rewriterules for different domains in htaccess file with WP multisite

If you wanted to target a specific domain then you need a condition (RewriteCond directive), preceding the RewriteRule that checks for the specific domain (Host: header). For example: RewriteCond %{HTTP_HOST} ^domainb\.com [NC] RewriteRule ^i-like-([a-zA-Z0-9-]+)/$ wp-content/themes/customtheme/custom-pages/ilike.php?like=$1 [L] The HTTP_HOST server variable contains just the Host: header sent in the request. Reference: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond

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

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