Last active
April 12, 2021 21:10
-
-
Save RhythmShahriar/4866118604c7257c33d60d0cd6a393b6 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Update the Permalink of a Specific Category | |
* | |
* @param $permalink | |
* @param $term | |
* @param $taxonomy | |
* | |
* @return mixed | |
*/ | |
function o360_archive_permalink( $permalink, $term, $taxonomy ) { | |
// Get the category ID | |
$category_id = $term->term_id; | |
// Check for desired category | |
if ( ! empty( $category_id ) ) { | |
if ( $category_id == 1 ) { | |
$permalink = trailingslashit( home_url( '/category/doctors/articles/' ) ); | |
} | |
elseif ( $category_id == 19 ) { | |
$permalink = trailingslashit( home_url( '/category/doctors/dental-equipments/' ) ); | |
} | |
elseif ( $category_id == 36 ) { | |
$permalink = trailingslashit( home_url( '/category/public/dental-implants/' ) ); | |
} | |
elseif ( $category_id == 22413 ) { | |
$permalink = trailingslashit( home_url( '/category/public/top-doctors/' ) ); | |
} | |
elseif ( $category_id == 26 ) { | |
$permalink = trailingslashit( home_url( '/category/doctors/dental-material/' ) ); | |
} | |
elseif ( $category_id == 21322 ) { | |
$permalink = trailingslashit( home_url( '/category/doctors/practice-management/' ) ); | |
} | |
elseif ( $category_id == 22414 ) { | |
$permalink = trailingslashit( home_url( '/category/doctors/lists/' ) ); | |
} | |
elseif ( $category_id == 22052 ) { | |
$permalink = trailingslashit( home_url( '/category/doctors/' ) ); | |
} | |
elseif ( $category_id == 21401 ) { | |
$permalink = trailingslashit( home_url( '/category/marketing-ideas/' ) ); | |
} | |
elseif ( $category_id == 29 ) { | |
$permalink = trailingslashit( home_url( '/category/public/orthodontics/' ) ); | |
} | |
elseif ( $category_id == 22051 ) { | |
$permalink = trailingslashit( home_url( '/category/public/' ) ); | |
} | |
} | |
return $permalink; | |
} | |
add_filter( 'term_link', 'o360_archive_permalink', 10, 3 ); | |
/** | |
* Update the rewrite rule for the specific category | |
* | |
* @param $wp_rewrite | |
* | |
* @return mixed | |
*/ | |
function o360_archive_rewrite_rules( $wp_rewrite ) { | |
$new_rules['^category/doctors/articles/?$'] = 'index.php?cat=1'; | |
$new_rules['^category/doctors/dental-equipments/?$'] = 'index.php?cat=19'; | |
$new_rules['^category/doctors/dental-material/?$'] = 'index.php?cat=26'; | |
$new_rules['^category/doctors/lists/?$'] = 'index.php?cat=22414'; | |
$new_rules['^category/doctors/practice-management/?$'] = 'index.php?cat=21322'; | |
$new_rules['^category/doctors/?$'] = 'index.php?cat=22052'; | |
$new_rules['^category/public/orthodontics/?$'] = 'index.php?cat=29'; | |
$new_rules['^category/public/top-doctors/?$'] = 'index.php?cat=22413'; | |
$new_rules['^category/public/dental-implants/?$'] = 'index.php?cat=36'; | |
$new_rules['^category/public/?$'] = 'index.php?cat=22051'; | |
$new_rules['^category/marketing-ideas/?$'] = 'index.php?cat=21401'; | |
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules; | |
return $wp_rewrite; | |
} | |
add_action( 'generate_rewrite_rules', 'o360_archive_rewrite_rules' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment