Skip to content

Instantly share code, notes, and snippets.

@vilius

vilius/user.php Secret

Last active May 27, 2017 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vilius/b0f8a279e13e50a6d18e0ca38ffe603d to your computer and use it in GitHub Desktop.
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
<?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