add_rewrite_rule – how to match exact whole word only?

Here’s the updated code with the explanation and last two lines added: Updated Code with Last Two Lines add_action(‘query_vars’, ‘add_query_vars’); function add_query_vars($vars) { $vars[] = ‘verify’; // Add ‘verify’ as a query variable return $vars; } add_action(‘init’, ‘verify_add_rewrite_rule’); function verify_add_rewrite_rule() { // Use ^verify/?$ to strictly match “verify” and ensure it ends there add_rewrite_rule(‘^verify/?$’, ‘index.php?verify=1&post_type=page’, … Read more

WordPress Page Slug with URL custom template

Eventually I found out a solution. Below is how I have achieved this. In my functions.php file, I have put below code. add_filter(‘query_vars’, ‘add_user_var’, 0, 1); function add_user_var($vars){ $vars[] = ‘user’; return $vars; } add_rewrite_rule(‘^user/([^/]+)/?$’,’index.php?pagename=user&user=$matches[1]’,’top’); This generally adds a rewrite rule if it finds user in the URL. Now I have added a page template … Read more

I’m building a WordPress theme and noticed that the 404 page template runs along with the corresponding templates for each page. Any idea why?

I used the following function to retrieve the URLs of each page. function template_debug($filename = null) { $url = home_url($_SERVER[‘REQUEST_URI’]); debug(“Called from: $filename using URL $url \n”); } Then I inspected the front page which triggered the 404 template along with the front-page template. The Network Monitor tab showed the error, which was an incorrect … Read more

Create Page with Template File from Plugin Folder

It is probably wp_insert_post can’t recognize your template. You need to include it in the list of the templates. function wpse410645_add_plugin_template( $page_templates ) { $page_templates[plugin_dir_path( __FILE__ ) . ‘/templates/mytemplate.php] = ‘My Template Name’; return $page_templates; } add_filter( ‘theme_page_templates’, ‘wpse410645_add_plugin_template’ );