Custom routing for plugins

The WordPress Way of doing it is using query_vars so first you add you vars to the array: //add to query vars function add_query_vars($vars) { $new_vars = array(‘custom_method’,’cm_parameter’); $vars = $new_vars + $vars; return $vars; } add_filter(‘query_vars’, ‘add_query_vars’); then you can check in your plugin for the vars: global $wp; if (array_key_exists(‘custom_method’, $wp->query_vars) && isset($wp->query_vars[‘custom_method’])){ … Read more

Custom URL routing based on cookie value

SESSION variables aren’t reliable, and won’t work on some WP hosts. Even worse, you’re going to prevent caching But more importantly, don’t route, redirect! Routing and redirecting are not the same thing So, we want the following logic: on the template_redirect action if the user is on the homepage aka is_home call wp_safe_redirect redirect to … Read more

Redirect sub-pages to parent without changing URL

No, you are on the right track as far as the add_rewrite_rule function is concerned. The generated rewrite rule doesn’t send a 303 header. The problem, in this case, is with your code which can be fixed easily. On this line: add_rewrite_rule(‘^recommendations\/(.*)\/?’, ‘recommendations/’, ‘top’); you are making WordPress to output a modified, custom .htaccess file … Read more

how do i create a specific handler for a url?

You could use the parse_request hook. For example: add_action( ‘parse_request’, function ( $wp ) { // Run your actions only if the current request path is exactly ‘image-generator’ // as in https://example.com/image-generator if the site URL is https://example.com if ( ‘image-generator’ === $wp->request ) { $a = $_GET[‘a’]; $b = $_GET[‘b’]; $etc=”etc”; // … your … Read more

wordpress – load a template based on the URI

I assume that your custom post type windows would map onto /windows/ etc? You can customise the template for individual custom post types via single-posttype.php in your theme, e.g. single-windows.php single-doors.php and single-garages.php WordPress will automatically pick these up You could also use custom page templates, e.g. page-windows.php or custom templates with the right template … Read more

WordPress and VueJS routing problem

This is the default WordPress .htaccess: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress Please add add the following line to it to prevent the default behavior for your custom route. RewriteCond %{REQUEST_URI} !^/my-vue-route/(.+) Like this: … Read more

REST API: No route was found matching the URL and request method

It’s because of how you’ve defined the accepted methods: ‘methods’ => ‘\WP_REST_Server::CREATABLE ‘, You shouldn’t have quotes around it. WP_REST_Server::CREATABLE is a string that equals ‘POST’, but by putting quotes around it you’re literally setting the method as ‘\WP_REST_Server::CREATABLE’, which is not a valid HTTP method. You can see this in the response to the … Read more

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