Site logo

Archived topic

Add page title to "leave a comment"

6 replies · Started by Anders Nielsen on May 13, 2022

Viewing posts 1–7 of 7

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';
}

Also if I can trigger this filter for only category "towns"

How can I do that ?

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;
}

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;
}

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';

Great ... thanks

You're welcome

This archived topic is closed to new replies.