treehouse : what would you like to learn today?
Web Design Web Development iOS Development

cant get it to work with an if statement wrap..

  • Hi, im using

    add_filter( 'the_title', 'wpse33385_filter_title', 10, 2 );
    function wpse33385_filter_title( $title, $post_id )
    {
    if( $new_title = get_post_meta( $post_id, 'custom_field_name', true ) )
    {
    return $new_title;
    }
    return $title;
    }

    That code, to display a different post title when the custom field value exists.. the code works, but when i add this if statement around it, since i only want the post title to be changed on single post pages, i dont get any errors, but the post title remains the regular post title

    if (is_single()) {
    add_filter( 'the_title', 'wpse33385_filter_title', 10, 2 );
    function wpse33385_filter_title( $title, $post_id )
    {
    if( $new_title = get_post_meta( $post_id, 'custom_field_name', true ) )
    {
    return $new_title;
    }
    return $title;
    }
    }


    im trying to get this to work, so i can then try to make it work for WooCommerce Product Single pages, if i could get any insight on that i would appreciate it seeing as how ill likely end up back here for help anyways :(

    Thanks!