‘rewrite_rules_array’ or ‘generate_rewrite_rules’ for adding custom rewrite rules?
This is possibly a matter of opinion, but I would say – neither. If you’re simply adding new rules, use add_rewrite_rule hooked to the init action.
This is possibly a matter of opinion, but I would say – neither. If you’re simply adding new rules, use add_rewrite_rule hooked to the init action.
As I mentioned in my comment, you can use add_rewrite_endpoint to accomplish this. First, add the endpoint: function wpa_author_endpoints(){ add_rewrite_endpoint( ‘liked-posts’, EP_AUTHORS ); } add_action( ‘init’, ‘wpa_author_endpoints’ ); After flushing rewrite rules (visit your Settings > Permalinks page in admin), author URLs can now be appended with /liked-posts/. Next, add a filter to author_template to … Read more
I think this does what you’re trying to achieve. Regarding multisite 404s, you have to flush rewrite rules on every site within multisite where you want this rule to get added. A quick method for testing purposes is to visit the permalinks settings page for each site you’re testing. Also note, I removed the .php … Read more
Thanks to @Milo on the comments, I’m gonna post my answer: Firstly I added this rule: add_rewrite_rule( “en/artist/([^/]+)/?”, ‘index.php?pagename=post_type=artist&artist=$matches[1]&gal_template=en’, “top”); Then this filter: add_filter( ‘query_vars’, ‘gal_query_vars’ ); function gal_query_vars( $query_vars ) { $query_vars[] = ‘gal_template’; return $query_vars; } Finally, I filtered the single template: add_filter( ‘single_template’, ‘get_custom_post_type_template’ ); function get_custom_post_type_template($single_template) { global $post; if ($post->post_type … Read more
If you tried to create a static file and then load it like a normal file, you may have had trouble because a WP page as we call it, is actually not actually 1 file, but rather a lot of files that tell WordPress how to put together information queried from the database based on … Read more
Yes it is possible, but there isn’t much point in that. The crudest way is to use a filter on the result of getting the ‘rewrite_rules’ option, and manipulating it by adding the entries you require directly to the array, and then you might need to filter those rules out when the option is updated. … Read more
This will allow you to use the post name without the slug. Essentially anytime the link is requested it can be altered to exclude the base post type. And any time a query runs with just a name, the available post types used in the search are altered to include your post type. function wpse_remove_cpt_slug( … Read more
You can use the init hook to check the $_REQUEST or $_GET super-global variable for your token value and then redirect to pages that are present via WP Core: home_url wp_login_url If you pass additional parameters to these URLs, such as token_valid=true you can use that along with conditional tags like is_front to conditionally display … Read more
For the list of authors, the simplest solution is to create a page with the slug author, then create a page-author.php template where you’ll add your own code to list authors. All views in WordPress are a post or list of posts- there’s no concept of an author list, or a list of terms in … Read more
I’m not sure if I should assume that you were issuing your examples inside of the init hook, but if not that is the reason they weren’t working for you. So inside functions.php function sd_rewrite_rules() { add_rewrite_tag(‘%domain_name%’, ‘([^&]+)’); add_rewrite_rule(‘^/([^/]*)/?’,’index.php?domain_name=$matches[1]’,’top’); } add_action(‘init’, ‘sd_rewrite_rules’, 10, 0); Then if you wanted to retrieve the query variable to do … Read more