Set URL Parameter Post Layout As Default

I want this to apply to all posts First off, making the content query string defaults to onepage is actually equivalent to enabling the onepage() for all URLs/pages. And for example to enable it by default on single post pages only (for any post types), then you can replace this: if( empty( $_GET[“content”] ) || … Read more

Creating a return url for getting data from external api

You could register a rest route (ref: https://developer.wordpress.org/reference/functions/register_rest_route/). In your case, something like this would do the trick: register_rest_route( ‘your-plugin/v1’, ‘/payments/(?P<trans_id>\d+)(?:/(?P<amount>\d+))?’, array( ‘methods’ => ‘GET’, ‘callback’ => array( $this, ‘your_callback_function’), ‘args’ => array( ‘trans_id’ => array( ‘validate_callback’ => function($param, $request, $key) { return is_numeric( $param ); } ), ‘amount’ => array( ‘validate_callback’ => function($param, $request, … Read more

Extra url paths as variable

The correct way to register the rewrite rule and rewrite tag for your case is: function custom_rewrite_rules() { add_rewrite_tag(‘%nights%’, ‘([^&]+)’); add_rewrite_tag(‘%people%’, ‘([^&]+)’); add_rewrite_rule(‘house/(.+)/(.+)/(.+)/?$’, ‘index.php?house=$matches[1]&nights=$matches[2]&people=$matches[3]’, ‘top’); } add_action(‘init’, ‘custom_rewrite_tag’, 10, 0); The code has been tested and works correctly.

Giving specific category posts its own permalink structure returns 404

First off, the add_rewrite_rule() syntax is add_rewrite_rule( ‘RegEx pattern’, ‘WordPress query string/vars’, ‘position/priority – top or bottom’ ). Now I could see you’re trying to have the following permalink structure: Structure: example.com/foodguide/<post ID>/<post slug> Example: example.com/foodguide/1/sample-food-guide But your rewrite rule (the second one in your code) does not have the proper RegEx subpattern for the … Read more