Created
October 10, 2011 17:28
-
-
Save chrisguitarguy/1275867 to your computer and use it in GitHub Desktop.
How to add fields to the WordPress permalinks page
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 | |
/* | |
Plugin Name: Custom-Post-Type Base | |
Plugin URI: http://pmg.co/ | |
Description: Dynamically change your custom post type slugs | |
Version: n/a | |
Author: Christopher Davis | |
Author URI: http://pmg.co/people/chris | |
License: GPL2/Creative Commons | |
*/ | |
add_action( 'load-options-permalink.php', 'wpse30021_load_permalinks' ); | |
function wpse30021_load_permalinks() | |
{ | |
if( isset( $_POST['wpse30021_cpt_base'] ) ) | |
{ | |
update_option( 'wpse30021_cpt_base', sanitize_title_with_dashes( $_POST['wpse30021_cpt_base'] ) ); | |
} | |
// Add a settings field to the permalink page | |
add_settings_field( 'wpse30021_cpt_base', __( 'CPT Base' ), 'wpse30021_field_callback', 'permalink', 'optional' ); | |
} | |
function wpse30021_field_callback() | |
{ | |
$value = get_option( 'wpse30021_cpt_base' ); | |
echo '<input type="text" value="' . esc_attr( $value ) . '" name="wpse30021_cpt_base" id="wpse30021_cpt_base" class="regular-text" />'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment