You can use template_include
, but before you hook to this filter you must do the following steps:
-
Create page template. e.g:
page-target.php
<?php /** * Template Name: Page Target */ ...
-
Manually query the contents of
target-page
onpage-target.php
template, because the global$post
will be referencing to yoursome-prefix-*
page. - (Optional): Edit and apply page template
Page Target
to your/target-page
from the Page Attributes
Then add the following to your functions.php
file
add_filter('template_include', function($template) {
global $post;
$prefix = 'some-prefix-'; // Your prefix
$prefixExist = strpos($post->post_name, $prefix) !== false;
if ($prefixExist) {
return locate_template('page-target.php'); //Your template
}
return $template;
});
Above filter will override the template with page-target.php
if condition met, otherwise default
Edit:
I think I have found a better way to resolve this using add_rewrite_rule
function custom_rewrite_basic() {
$page_id = 123; //Your serve page id
add_rewrite_rule('^some-prefix-.*', 'index.php?page_id=' . $page_id, 'top');
}
add_action('init', 'custom_rewrite_basic');
IMPORTANT: Do not forget to flush and regenerate the rewrite rules database after modifying rules. From WordPress Administration Screens, Select Settings -> Permalinks and just click Save Changes without any changes.