0

I have a multilingual plugin that translates the pages. For example, after I press the language button the URL changes from example.com/products to example.com/en/products. My problem is that I want to redirect from the page example.com/en/products to another page but this page doesn't exist in my Pages list because it is created by the plugin. And 301 redirect plugins can't find this page.

How to handle such cases?

0

What you can do is save the ID of page you programatically created in options table.

add_option( 'my_plugin_dynamic_page_id', YOUR_PAGE_ID_HERE);

Now you can get the page you created easily anytime you want. Following way.

$pageID = get_option( 'my_plugin_dynamic_page_id', true);

Then you can get the permalink to the page once you get the page ID. And redirect user to the permalink.

$permalink = get_permalink($pageID);
wp_redirect( $permalink );
exit;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.