Friday, 26 March 2021

Custome URL with theme directory

 Custome URL with theme directory


wp

'-> wp-content



function.php

-------------

add_action('init', function() {

$url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/');

$re = '/string-one\/(.*)\/string-two/';

preg_match($re, $url_path, $matches, PREG_OFFSET_CAPTURE, 0);

if ( $matches ) {

$load = locate_template('template.php', true);

if ($load) {

exit(); 

}

}

});


template.php

------------

get_header();

$url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/');

$re = '/string-one\/(.*)\/string-two/';

preg_match($re, $url_path, $matches, PREG_OFFSET_CAPTURE, 0);

print_r($mathes);

No comments:

Post a Comment