Last active
August 28, 2015 16:12
-
-
Save jamigibbs/bee04c3e9c1e6b026d7b to your computer and use it in GitHub Desktop.
Change Slug of a Plugin's Custom Post Type
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 | |
/** | |
* Change Beer Directory plugin slug from 'beer' to 'soup' | |
* | |
* @link http://wordpress.stackexchange.com/questions/41988/redeclare-change-slug-of-a-plugins-custom-post-type | |
*/ | |
function brewery_add_custom_rewrite_rule() { | |
// First, try to load up the rewrite rules. We do this just in case | |
// the default permalink structure is being used. | |
if( ($current_rules = get_option('rewrite_rules')) ) { | |
// Next, iterate through each custom rule adding a new rule | |
// that replaces 'beer' with 'soup' and give it a higher | |
// priority than the existing rule. | |
foreach($current_rules as $key => $val) { | |
if(strpos($key, 'beer') !== false) { | |
add_rewrite_rule(str_ireplace('beer', 'soup', $key), $val, 'top'); | |
} // end if | |
} // end foreach | |
} // end if/else | |
// ...and we flush the rules | |
flush_rewrite_rules(); | |
} // end add_custom_rewrite_rule | |
add_action('init', 'brewery_add_custom_rewrite_rule'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment