add_rewrite_rule wordpress ignoring url pattern, wp rewrite not working

You are trying to match 7-number-cities-starting-with-pa URL to ^([^/]*)-letter-words-starting-with- pattern in second rule. These rules should work: add_action( ‘init’ , ‘se336474_rewrite_rules’, 5 ); add_filter( ‘query_vars’, ‘se336474_query_vars’ ); function se336474_rewrite_rules() { // single pattern for URLs: // site.com/cities-starting-with-pa/ => start_letter=”pa” // site.com/7-cities-starting-with-pi/ => start_letter=”pi”, length=7 add_rewrite_rule( ‘^(?:([0-9]+)-)?cities-starting-with-([^/]*)/?$’, ‘index.php?page_id=340&start_letter=$matches[2]&length=$matches[1]’, ‘top’ ); // // OR for URLs: // … Read more

Add slug to default post permalinks ONLY

Literally found the answer 10 minutes after posting this question and spending a couple of hours on it before asking. Simply hook your function to post_link! 🤦 public function __construct() { add_action(‘post_link’, [$this, ‘post_links’], 10, 2); } public function post_links($link, $post) { if ($post->post_type === ‘post’) { return site_url(‘slug/’. $post->post_name .’-‘. $post->ID); } else { … Read more