Skip to content

Brug WordPress rewrite rules til custom theme page

function zebs_custom_rewrite() {

// registers the mit_plugin and module query variable. WP will reject unkown variabels
add_rewrite_tag('%mit_plugin%','([^&]+)');
add_rewrite_tag('%module%','([^&]+)');

// handles site.dk/mit-plugin and mudule such as site.dk/mit-plugin/mod    add_
rewrite_rule(
'mit-plugin(/.*)?/?$',
'index.php?mit_plugin=all&module=$matches[1]',
'top'
);
}
// add function to init
add_action( 'init', 'zebs_custom_rewrite', 99 );
// flush_rules() if our rules are not yet included
function zebs_flush_rules() {
// get the rules from WP
$rules = get_option( 'rewrite_rules' );

// check to se if the rules is there
if ( ! isset( $rules['mit-plugin/(.*)$'] ) ) {
// if missing flush
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
add_action( 'wp_loaded', 'zebs_flush_rules' );
function zebs_template( $template ){
global $wp_query;

if ( 'all' == get_query_var('mit-plugin') ) {
$template = get_stylesheet_directory() . '/page-mit-plugin.php';
}

return $template;
}
add_filter( 'template_include', 'zebs_template' );

Comments (0)

Skriv et svar

Back To Top