Title: Patch to add &quot;rewrite=&gt;with_front&quot; functionality
Last modified: August 20, 2016

---

# Patch to add "rewrite=>with_front" functionality

 *  Resolved [MarcGuay](https://wordpress.org/support/users/marcguay/)
 * (@marcguay)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/patch-to-add-rewritewith_front-functionality/)
 * I needed this feature in my version of CPT UI. Here’s a simple patch to add it.
   Hopefully it will be added to the released version, I don’t see a reason not 
   to.
 * Cheerios
    Marc
 *     ```
       Index: custom-post-type-ui.php
       ===================================================================
       --- custom-post-type-ui.php	(revision 651445)
       +++ custom-post-type-ui.php	(working copy)
       @@ -128,7 +128,7 @@
        				'capability_type' => $cpt_post_type["capability_type"],
        				'hierarchical' => get_disp_boolean($cpt_post_type["hierarchical"]),
        				'exclude_from_search' => $cpt_exclude_from_search,
       -				'rewrite' => array('slug' => $cpt_rewrite_slug),
       +				'rewrite' => array('slug' => $cpt_rewrite_slug, 'with_front' => $cpt_post_type["rewrite_with_front"] ),
        				'query_var' => get_disp_boolean($cpt_post_type["query_var"]),
        				'description' => esc_html($cpt_post_type["description"]),
        				'menu_position' => $cpt_menu_position,
       @@ -178,7 +178,7 @@
        				'label' => $cpt_label,
        				'show_ui' => get_disp_boolean($cpt_tax_type["show_ui"]),
        				'query_var' => get_disp_boolean($cpt_tax_type["query_var"]),
       -				'rewrite' => array('slug' => $cpt_rewrite_slug),
       +				'rewrite' => array('slug' => $cpt_rewrite_slug, 'with_front' => $cpt_tax_type["rewrite_with_front"] ),
        				'singular_label' => $cpt_singular_label,
        				'labels' => $cpt_labels
        			) );
       @@ -553,6 +553,7 @@
                            <th><?php _e('Show UI', 'cpt-plugin');?></th>
                            <th><?php _e('Hierarchical', 'cpt-plugin');?></th>
                            <th><?php _e('Rewrite', 'cpt-plugin');?></th>
       +                    <th><?php _e('Rewrite With Front', 'cpt-plugin' );?></th>
                            <th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
                            <th><?php _e('Total Published', 'cpt-plugin');?></th>
                            <th><?php _e('Total Drafts', 'cpt-plugin');?></th>
       @@ -568,6 +569,7 @@
                            <th><?php _e('Show UI', 'cpt-plugin');?></th>
                            <th><?php _e('Hierarchical', 'cpt-plugin');?></th>
                            <th><?php _e('Rewrite', 'cpt-plugin');?></th>
       +                    <th><?php _e('Rewrite With Front', 'cpt-plugin' );?></th>
                            <th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
                            <th><?php _e('Total Published', 'cpt-plugin');?></th>
                            <th><?php _e('Total Drafts', 'cpt-plugin');?></th>
       @@ -597,6 +599,7 @@
                        <td valign="top"><?php echo disp_boolean($cpt_post_type["show_ui"]); ?></td>
                        <td valign="top"><?php echo disp_boolean($cpt_post_type["hierarchical"]); ?></td>
                        <td valign="top"><?php echo disp_boolean($cpt_post_type["rewrite"]); ?></td>
       +                <td valign="top"><?php echo disp_boolean($cpt_post_type["rewrite_with_front"]); ?></td>
                        <td valign="top"><?php echo $rewrite_slug; ?></td>
                        <td valign="top"><?php echo $cpt_counts->publish; ?></td>
                        <td valign="top"><?php echo $cpt_counts->draft; ?></td>
       @@ -663,7 +666,7 @@
        						$custom_post_type .= 	'\'show_in_menu\' => ' .$cpt_show_in_menu .',';
        						$custom_post_type .= 	'\'capability_type\' => \''.$cpt_post_type["capability_type"].'\',';
        						$custom_post_type .= 	'\'hierarchical\' => '.disp_boolean($cpt_post_type["hierarchical"]).',';
       -						$custom_post_type .= 	'\'rewrite\' => array(\'slug\' => \'' .$cpt_post_type["rewrite_slug"]. '\'),';
       +						$custom_post_type .= 	'\'rewrite\' => array(\'slug\' => \'' .$cpt_post_type["rewrite_slug"]. '\', \'with_front\' => \'' .$cpt_post_type["rewrite_with_front"]. '\'),';
        						$custom_post_type .= 	'\'query_var\' => '. disp_boolean($cpt_post_type["query_var"]).',';
   
        						if ( $cpt_post_type["has_archive"] ) {
       @@ -822,6 +825,7 @@
                        <th><?php _e('Hierarchical', 'cpt-plugin');?></th>
                        <th><?php _e('Show UI', 'cpt-plugin');?></th>
                        <th><?php _e('Rewrite', 'cpt-plugin');?></th>
       +                <th><?php _e('Rewrite With Front', 'cpt-plugin');?></th>
                        <th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
                        </tr>
                    </thead>
       @@ -835,6 +839,7 @@
                        <th><?php _e('Hierarchical', 'cpt-plugin');?></th>
                        <th><?php _e('Show UI', 'cpt-plugin');?></th>
                        <th><?php _e('Rewrite', 'cpt-plugin');?></th>
       +                <th><?php _e('Rewrite With Front', 'cpt-plugin');?></th>
                        <th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
                        </tr>
                    </tfoot>
       @@ -869,6 +874,7 @@
                        <td valign="top"><?php echo disp_boolean($cpt_tax_type["hierarchical"]); ?></td>
                        <td valign="top"><?php echo disp_boolean($cpt_tax_type["show_ui"]); ?></td>
                        <td valign="top"><?php echo disp_boolean($cpt_tax_type["rewrite"]); ?></td>
       +                <td valign="top"><?php echo disp_boolean($cpt_tax_type["rewrite_with_front"]); ?></td>
                        <td valign="top"><?php echo $rewrite_slug; ?></td>
                    </tr>
                	<tr>
       @@ -905,7 +911,7 @@
                                        $custom_tax .= 	'\'label\' => \''.$cpt_label.'\',';
                                        $custom_tax .= 	'\'show_ui\' => '.disp_boolean($cpt_tax_type["show_ui"]).',';
                                        $custom_tax .= 	'\'query_var\' => '. disp_boolean($cpt_tax_type["query_var"]).',';
       -				$custom_tax .= 	'\'rewrite\' => array(\'slug\' => \'' .$cpt_tax_type["rewrite_slug"]. '\'),';
       +				$custom_tax .= 	'\'rewrite\' => array(\'slug\' => \'' .$cpt_tax_type["rewrite_slug"]. '\', \'with_front\' => \'' .$cpt_tax_type["rewrite_with_front"]. '\'),';
                                        $custom_tax .= 	'\'singular_label\' => \''.$cpt_singular_label.'\'';
                                        $custom_tax .= ') );';
   
       @@ -961,6 +967,7 @@
        	$cpt_capability = $cpt_options[$editType]["capability_type"];
        	$cpt_hierarchical = $cpt_options[$editType]["hierarchical"];
        	$cpt_rewrite = $cpt_options[$editType]["rewrite"];
       +    $cpt_rewrite_with_front = $cpt_options[$editType]["rewrite_with_front"];
        	$cpt_rewrite_slug = $cpt_options[$editType]["rewrite_slug"];
        	$cpt_query_var = $cpt_options[$editType]["query_var"];
        	$cpt_description = $cpt_options[$editType]["description"];
       @@ -996,6 +1003,7 @@
        	$cpt_tax_showui = $cpt_options[$editTax]["show_ui"];
        	$cpt_tax_query_var = $cpt_options[$editTax]["query_var"];
        	$cpt_tax_rewrite = $cpt_options[$editTax]["rewrite"];
       +	$cpt_tax_rewrite_with_front = $cpt_options[$editTax]["rewrite_with_front"];
        	$cpt_tax_rewrite_slug = $cpt_options[$editTax]["rewrite_slug"];
        	$cpt_tax_labels = $cpt_options[$editTax][0];
        	$cpt_post_types = $cpt_options[$editTax][1];
       @@ -1225,6 +1233,16 @@
                            </tr>
   
                            <tr valign="top">
       +                    <th scope="row"><?php _e('Rewrite With Front', 'cpt-plugin') ?></th>
       +                    <td>
       +                        <SELECT name="cpt_custom_post_type[rewrite_with_front]" tabindex="8">
       +                            <OPTION value="0" <?php If (isset($cpt_rewrite_with_front)) { If ($cpt_rewrite_with_front == 0 && $cpt_rewrite_with_front != '') { echo 'selected="selected"'; } } ?>>False</OPTION>
       +                            <OPTION value="1" <?php If (isset($cpt_rewrite_with_front)) { If ($cpt_rewrite_with_front == 1 || is_null($cpt_rewrite_with_front)) { echo 'selected="selected"'; } }Else{ echo 'selected="selected"'; } ?>>True</OPTION>
       +                        </SELECT> <a href="#" title="" style="cursor: help;">?</a> (default: True)
       +                    </td>
       +                    </tr>
       +
       +                    <tr valign="top">
                            <th scope="row"><?php _e('Custom Rewrite Slug', 'cpt-plugin') ?></th>
                            <td><input type="text" name="cpt_custom_post_type[rewrite_slug]" tabindex="9" value="<?php If (isset($cpt_rewrite_slug)) { echo esc_attr($cpt_rewrite_slug); } ?>" /> <a href="#" title="Custom Post Type Rewrite Slug" style="cursor: help;">?</a> (default: post type name)</td>
                            </tr>
       @@ -1469,6 +1487,15 @@
                            </tr>
   
                            <tr valign="top">
       +                    <th scope="row"><?php _e('Rewrite With Front', 'cpt-plugin') ?></th>
       +                    <td>
       +                        <SELECT name="cpt_custom_tax[rewrite_with_front]" tabindex="28">
       +                            <OPTION value="0" <?php If (isset($cpt_tax_rewrite_with_front)) { If ($cpt_tax_rewrite_with_front == 0 && $cpt_tax_rewrite_with_front != '') { echo 'selected="selected"'; } } ?>>False</OPTION>
       +                            <OPTION value="1" <?php If (isset($cpt_tax_rewrite_with_front)) { If ($cpt_tax_rewrite_with_front == 1 || is_null($cpt_tax_rewrite_with_front)) { echo 'selected="selected"'; } }Else{ echo 'selected="selected"'; } ?>>True</OPTION>
       +                        </SELECT> <a href="#" title="" style="cursor: help;">?</a> (default: True)
       +                    </td>
       +                    </tr><br />
       +                    <tr valign="top">
                            <th scope="row"><?php _e('Custom Rewrite Slug', 'cpt-plugin') ?></th>
                            <td><input type="text" name="cpt_custom_tax[rewrite_slug]" tabindex="9" value="<?php If (isset($cpt_tax_rewrite_slug)) { echo esc_attr($cpt_tax_rewrite_slug); } ?>" /> <a href="#" title="Custom Taxonomy Rewrite Slug" style="cursor: help;">?</a> (default: taxonomy name)</td>
                            </tr>
       ```
   
 * [http://wordpress.org/extend/plugins/custom-post-type-ui/](http://wordpress.org/extend/plugins/custom-post-type-ui/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [dhavaljani](https://wordpress.org/support/users/dhavaljani/)
 * (@dhavaljani)
 * [13 years ago](https://wordpress.org/support/topic/patch-to-add-rewritewith_front-functionality/#post-3374298)
 * Thanks Brad for a great plugin. I agree with MarcGuay as I needed that option
   too and I found lot of posts and questions about how to add “rewrite=>with_front”
   functionality and even a fork of this plugin [http://stephennomura.com/blog/enhanced-version-of-custom-post-types-ui](http://stephennomura.com/blog/enhanced-version-of-custom-post-types-ui)
   but I would rather that it was in original plugin as its already installed and
   being used on the site.
 * MarcGuay Can you provide some details on how to apply this patch?
 * Thanks.
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [12 years, 11 months ago](https://wordpress.org/support/topic/patch-to-add-rewritewith_front-functionality/#post-3374318)
 * Making parameters for all of the options available to the register functions 
   will be a priority for the next release. Not sure why it wasn’t part of the original.
 *  [eliot.eshelman](https://wordpress.org/support/users/elioteshelman/)
 * (@elioteshelman)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/patch-to-add-rewritewith_front-functionality/#post-3374338)
 * Thanks for this excellent plugin!
 * I’m using version 0.8 and see that “rewrite=>with_front” is supported for custom
   post types.
 * Can I inquire as to why support was not added for setting with_front on custom
   taxonomies? I’ve temporarily patched the version on my site.
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [12 years, 7 months ago](https://wordpress.org/support/topic/patch-to-add-rewritewith_front-functionality/#post-3374339)
 * eliot.esheiman
 * didn’t realize it was available for taxonomies as well. I’ll create an issue 
   for it on the associated GitHub repo.
 * [https://github.com/WebDevStudios/custom-post-type-ui](https://github.com/WebDevStudios/custom-post-type-ui)
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [12 years, 7 months ago](https://wordpress.org/support/topic/patch-to-add-rewritewith_front-functionality/#post-3374340)
 * Currently scheduled to be a part of 0.9, which is the 2nd-to-next release planned

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Patch to add "rewrite=>with_front" functionality’ is closed to new replies.

 * ![](https://ps.w.org/custom-post-type-ui/assets/icon-256x256.png?rev=2744389)
 * [Custom Post Type UI](https://wordpress.org/plugins/custom-post-type-ui/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-post-type-ui/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-post-type-ui/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-post-type-ui/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-post-type-ui/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-post-type-ui/reviews/)

 * 5 replies
 * 4 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/patch-to-add-rewritewith_front-functionality/#post-3374340)
 * Status: resolved