SEO Friendly URL on dynamic product page produced via shortcode

Your rule needs a little tweak. You also need to add id to valid query vars. function wpd_test_rule() { add_rewrite_tag( ‘%id%’, ‘([0-9]+)’ ); add_rewrite_rule( ‘^product/([0-9]+)/([^/]+)/?$’, ‘index.php?page_id=5&id=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘wpd_test_rule’ ); Note that WordPress doesn’t put query vars in $_GET, you’ll need to adjust your code to use get_query_var(‘id’) to fetch the value. … Read more

How to change old permalink?

Well you have several options, but you definitely need to redirect the url. You can either achieve the redirection via a WordPress plugin or through your .htaccess file. If you would like to use a plugin, I would recommend “Redirection” by John Godley. It is easy to use. Just type the url you want to … Read more

How to 301 redirect from one url to another properly

Generally, you can use .htaccess (a file located at the root of the folder you are serving) and a regular expression to do the redirect. I used Yoast to generate mine: RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(?!page/)(.+)$ https://example.com/$4 In the regular expression above I match anything at the beginning then I match / followed by 4 digits (a … Read more

Programmatically Restrict WordPress from using certain URLs or sub-directories

The easiest way in WP would be to use wp_unique_post_slug hook. It takes 6 params: apply_filters( ‘wp_unique_post_slug’, string $slug, int $post_ID, string $post_status, string $post_type, int $post_parent, string $original_slug ) So you can target given URL and modify the slug would conflict. Let’s say you want to prevent WP from using website.com/eat address. All you … Read more

Custom permalink structure: /%custom-taxonomy%/%post-name%/ (without CPT slug)

I managed to find a solution $args = array( ‘labels’ => $labels, ‘public’ => true, ‘publicly_queryable’ => true, ‘show_ui’ => true, ‘show_in_menu’ => true, ‘query_var’ => true, ‘rewrite’ => array ( ‘slug’ => ‘products/%catalogs%’, ‘with_front’ => false), ‘capability_type’ => ‘post’, ‘has_archive’ => ‘products’, ‘hierarchical’ => false, ‘menu_position’ => 4, ‘menu_icon’ => ‘dashicons-cart’, ‘supports’ => array( … Read more

Removing leading zeros from custom permalink structure

How about using custom rewrite tags/structure? So we’ll be using these two rewrite/structure tags: %monthnum2% does the same thing as the %monthnum% tag, but without a leading zero; e.g. 3 and not 03 for March. %day2% does the same thing as the %day% tag, but without a leading zero; e.g. 7 and not 07. The … Read more

Using taxonomy term in CPT permalink – Pages 404’s

Ended up with commenting out line 4 and changing the filter into this: add_filter(‘post_type_link’, function ( $post_link, $post, $id = 0 ) { if ( ‘project’ != $post->post_type || ‘publish’ != $post->post_status ) { return $post_link; } $post = get_post($id); if (is_object( $post ) && $post->post_type == ‘project’ ) { $terms = wp_get_object_terms( $post->ID, ‘department’ … Read more