Skip to content

Instantly share code, notes, and snippets.

@jamigibbs
Last active August 28, 2015 16:12
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 jamigibbs/bee04c3e9c1e6b026d7b to your computer and use it in GitHub Desktop.
Save jamigibbs/bee04c3e9c1e6b026d7b to your computer and use it in GitHub Desktop.
Change Slug of a Plugin's Custom Post Type
<?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