1

I am using this code to return the title of the post on a gravity form field.

add_filter('gform_field_value_page_name', 'page_name_filler');
    function page_name_filler($value){
        return get_the_title() ; 
    }

However, usually the title of the post is too long and it overfills the field. Hence I would only like to retain the first portion of the title before a comma "," if it exists on the title. Usually I will have multiple commas on my titles.

If a comma doesn't exist then the full title should be displayed.

3

Use strtok():

return strtok( get_the_title(), ',' );

You could also use my function utf8_truncate(). This is a little bit more flexible and it can handle long strings without a comma.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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