Dear all,
I am trying to debug the rewrite rules created via wp_rewrite_rule() on WordPress 5.6.
I am seeing a strange phenomenon on my hosting, which I thought might have something to do with caching.
The rewrite rules are there but the rewriting is not “always” happening, as if the rules not being flushed. I attempted to flush via Permalinks page, clear browser cache, turn off Siteground cache, etc.
I installed a totally clean wordpress site to just go back to the most basic functions to see whether they work.
To make things extremely simple on this clean site with default Twenty Twenty theme, I only have 1 custom plug-in called “my-test-plugin” under which only 1 file called “my-test-plugin.php”.
function brb_test_this(){
global $wp_rewrite;
var_dump($wp_rewrite);
}
add_shortcode('brb_my_test_page', 'brb_test_this');
add_action( 'init', 'brb_test_rewrite', 10, 0);
function brb_test_rewrite(){
add_rewrite_rule('^fantastic-test/$', 'index.php?pagename=beautiful-day', 'top');
}
When I go to URL mysite.com/fantastic-test/, it should direct me to mysite.com/beautiful-day/ page but it is not happening.
I also tried adding “flush_rewrite_rules()” in brb_test_rewrite() as well as using both ‘top’ and ‘bottom’ priority tag.
On /beautiful-day page, we do see that $wp_rewrite has ^fantastic-test/$ rewrite rule included in the array.
What am I missing here? Thank you very much!
Best wishes,
Cindy L.
The page I need help with: [log in to see the link]