Skip to content

Instantly share code, notes, and snippets.

@djrmom
Created May 7, 2019 18:48
Show Gist options
  • Save djrmom/e8cf2655dabb8391b0df6addd919a00e to your computer and use it in GitHub Desktop.
Save djrmom/e8cf2655dabb8391b0df6addd919a00e to your computer and use it in GitHub Desktop.
facetwp comments in layout builder
<?php
/** output comments in layout builder
** add a placeholder (Post ID is a good choice) to layout builder and name it comment-output
** replace the value with the filter below
** to change the template file for the output if you need it different comments on
** single posts, copy comments.php to a new file (ie - comments-builder.php)
** and include the file name in the function - comments_template( '/comments-builder.php' );
**/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'comment-output' == $item['settings']['name'] ) {
global $withcomments;
$withcomments = "1";
ob_start();
if ( comments_open() || get_comments_number() ) {
comments_template();
}
$value = ob_get_clean();
}
return $value;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment