WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Have you ever tried http://www.wproots.com/ultimate-guide-to-meta-boxes-in-wordpress/ ? It's good classes to create metabox. But I'm having problem with the validation.

I tried the sanitize_callback parameter to sanitize URL, so I used esc_url but the field still accepted all values. What is the problem here?

Here's my code

add_smart_meta_box( 'themename_slides_url', array(

    'title'     => __( 'Slides Options', 'themename' ),
    'pages'     => array( 'slides' ),
    'context'   => 'normal',
    'priority'  => 'high',
    'fields'    => array(
            'name' => __( 'Slides URL', 'themename' ),
            'id' => 'slide_url',
            'default' => '',
            'desc' => __( 'Type the URL of the slide', 'themename' ),
            'type' => 'text',
            'sanitize_callback' => 'themename_sanitize_url'


function themename_sanitize_url( $new, $meta_key, $id ) {

    if( esc_url( $new ) )
        return $new;


Any idea ?

share|improve this question

esc_url() is not a validator. Use PHP’s filter functions for that.


// $url is now an URL or FALSE
$url = filter_var( 'http://example.com', FILTER_VALIDATE_URL );

if ( $url )
    # update post meta
    # delete post meta
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.