Tuesday, February 14, 2023
HomeWordPress Developmenturl rewriting - Utilizing a variable in web page permalink

url rewriting – Utilizing a variable in web page permalink


As I mentioned, the permalink adjustments from YEAR_NAME to 2023, however the
hyperlink will get 404 error

Sure, and it is as a result of the put up slug now not matched the worth within the database (within the wp_posts desk, column post_name), therefore the permalink URL grew to become invalid and WordPress displayed a 404 error web page.

So you should add a rewrite rule for dealing with the 12 months worth which replaces the TOP_NAME within the slug.

This is an instance you may strive, and you may change the ^top_in_2023 with ^top_in_d{4} as an alternative in order that it matches any 4-digit 12 months:

add_action( 'init', operate() {
    add_rewrite_rule(
        '^top_in_2023',
        // for Pages, the question var is pagename
        'index.php?pagename=top_in_YEAR_NAME',
        'high'
    );
} );

Keep in mind to flush the rewrite guidelines, by merely visiting the Permalink Settings admin web page.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments