Kind of a 2 part problem... there is the code to execute what you want, and then the code to place the element on the page. Below is the functions.php code needed to place the text box on the page edit page:Hello im trying to add an input field to wordpress pages > "Edit Page".
My purpose for this input field is for the user to add the shortcode of a slider, so that that slider will be page specific.
// Add custom Slider to 'Edit Page'
add_action( 'add_meta_boxes', 'cd_meta_box_add' );
function cd_meta_box_add() {
add_meta_box( 'my-meta-box-id', 'Slider', 'cd_meta_box_cb', 'page', 'normal', 'high' );
}
function cd_meta_box_cb( $post ) {
$values = get_post_custom( $post->ID );
$text = isset( $values['my_meta_box_text'] ) ? esc_attr( $values['my_meta_box_text'][0] ) : '';
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
?>
<p>
<label for="my_meta_box_text">Add a slider ID</label>
<input type="text" name="my_meta_box_text" id="my_meta_box_text" value="<?php echo $text; ?>" />
</p>
<?php
}
add_action( 'save_post', 'meta_box_save' );
function meta_box_save( $post_id ) {
// release if auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// bypass if data is not present
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
// bypass if user data does not allow
if( !current_user_can( 'edit_post', $post_id ) ) return;
// portion that saves data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchors can only have href attribute
)
);
// ensuring data is set
if( isset( $_POST['my_meta_box_text'] ) )
update_post_meta( $post_id, 'my_meta_box_text', wp_kses( $_POST['my_meta_box_text'], $allowed ) );
}
<?php echo do_shortcode( '[customslider id="' . get_post_meta(get_the_ID(), 'my_meta_box_text', true) . '"]'); ?>
$100 to your Paypal
300 Trophy Points
1 banner ad 728x 90
Referral link for :
Webmaster Sun is a forum where you’ll find in-depth discussions and resources to help you succeed on the web whether you are new or experienced. You’ll find it all here. With topics ranging from internet marketing, search engine optimization, social networking, make money online, web hosting, affiliate marketing as well as hands-on technical support for web design, programming and more. We are a growing community of like-minded people that is keen to help and support each other with ambitions and online endeavors. Learn and grow, make friends and contacts for life.
The world's smartest webmasters and internet marketers come here to discuss & share what's trending in the online marketing world!