[Resolved] Add page title to “leave a comment”

Home Forums Support [Resolved] Add page title to “leave a comment”

Home Forums Support Add page title to “leave a comment”

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2218913
    Anders Nielsen

    How do I add the page title to the comments?

    I have found the filer, but need a little more.

    add_filter( ‘generate_leave_comment’,’tu_custom_leave_comment’ );
    function tu_custom_leave_comment() {
    return ‘Leave a comment about PAGE-TITLE_HERE‘;
    }

    This is my site: GoTeam.dk

    #2218915
    Anders Nielsen

    Also if I can trigger this filter for only category “towns”

    How can I do that ?

    This is my site: GoTeam.dk

    #2218998
    Ying
    Staff
    Customer Support

    Try this:

    add_filter( 'generate_leave_comment','tu_custom_leave_comment', 10, 2 );
    function tu_custom_leave_comment() {
        $title = get_the_title();
        $default = 'Leave a Comment';
    	if( in_category('towns')){
                return 'Leave a comment about '.$title;
    	}
    	return $default;
    }
    #2219104
    Anders Nielsen

    works… but I can’t add a “?” or any other text behind the title?

    add_filter( ‘generate_leave_comment’,’tu_custom_leave_comment’, 10, 2 );
    function tu_custom_leave_comment() {
    $title = get_the_title();
    $default = ‘Leave a Comment’;
    if( in_category(‘towns’)){
    return ‘Leave a comment about ‘.$title; ? THIS FAILS
    }
    return $default;
    }

    This is my site: GoTeam.dk

    #2219562
    David
    Staff
    Customer Support

    Hi there,

    try this:

    return 'Leave a comment about '.$title .'?';

    or

    return 'Leave a comment about '. $title .'any text after must also be inside single straight quotes';

    #2219702
    Anders Nielsen

    Great … thanks

    This is my site: GoTeam.dk

    #2219970
    David
    Staff
    Customer Support
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.