-
-
Save vilius/b0f8a279e13e50a6d18e0ca38ffe603d to your computer and use it in GitHub Desktop.
Removes base from Fluxus theme portfolio URL structure to: /project-type/project-slug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fluxus_custom_permastruct() { | |
$project_types = get_terms( array( | |
"taxonomy" => "fluxus-project-type", | |
"fields" => "slugs", | |
"get" => "all" | |
) ); | |
$project_type_matcher = join( "|", array_map( "preg_quote", $project_types ) ); | |
add_rewrite_tag( "%fluxus-project-type%", "(${project_type_matcher})", "fluxus-project-type=" ); | |
remove_permastruct( "fluxus-project-type" ); | |
add_permastruct( "fluxus-project-type", "%fluxus-project-type%", false ); | |
remove_permastruct( "fluxus_portfolio" ); | |
add_permastruct( "fluxus_portfolio", "%fluxus-project-type%/%fluxus_portfolio%", false ); | |
remove_permastruct( "fluxus-project-type-default" ); | |
remove_permastruct( "fluxus_portfolio-default" ); | |
} | |
add_action( "init", "fluxus_custom_permastruct" ); | |
/** | |
* Never under-estimate the complexity of Wordpress... | |
* When using add_permastruct additional rules are created. | |
* Those rules break URL matching. Since they are not used we simply remove them here. | |
*/ | |
function fluxus_remove_attachment_rules( $rules ) { | |
foreach ( $rules as $rule => $redirect ) { | |
if ( false !== strpos( $redirect, "attachment=" ) ) { | |
unset( $rules[$rule] ); | |
} | |
} | |
return $rules; | |
} | |
add_filter( "fluxus_portfolio_rewrite_rules", "fluxus_remove_attachment_rules", 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment