Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End cant get it to work with an if statement wrap..

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #38607
    mikeman
    Member

    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)
  • The forum ‘Back End’ is closed to new topics and replies.