I have a specific page on my wordpress website example.com/download/
that I already have a page for. I would like to add some sort of php code to enable the following functionality.
/download/<name>
, I would like to fetch a file from some directory based on <name>
/download/
) I want to display the page that is already writtenIs this possible with Wordpress hooks/filters?
I have a feeling it has something to do with the WP_Rewrite class, but I am not sure exactly what to write, nor where to put it without WP or theme updates wiping the code
Yes, you have to add a custom rewrite rule. You can use your theme's functions.php to add the new functionality.
function custom_rewrite_rule() {
add_rewrite_rule('^download\/([^/]+)\/?','your_url_to_the_downloader_file.php?download=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
To make it work, first you need to go to Admin -> Settings -> Permalinks
and click the save button so the new rule is added.