Grow your CSS skills. Land your dream job.

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

  • # June 21, 2012 at 3:10 pm

    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!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".