How to add WORDPRESS comments widget to Brizy blog post template
4 minutos de lectura
Introduction
Brizy PRO is my preferred page builder for WordPress. It has almost everything. However, one feature it still lacks today is the integration with native WordPress comments for blog posts.
In this guide, I'll share how I solved this.
A shortcode for WordPress comments
The first problem to solve is that (as far as I could find out) there isn't a shortcode that allows us to insert the WordPress comments widget in, for example, a Brizy template. Brizy allows you to add existing shortcodes from your WordPress (native or from any other installed plugin), but it doesn't have one for comments. It's one of those rare things about WordPress that I've never understood.
My own plugin to have a comments shortcode
After trying several approaches, I found that you can "easily" load a new shortcode in WordPress by adding this PHP code, for example, in the functions.php file of your current theme:
<?php
/*
Plugin Name: My Comments Shortcode
Plugin URI:
Description: Lets you to use shortcode [wpse_comments_template] to insert native Wordpress post comments.
Version: 1.0
Author: IMASDEWEB
License: GPL v2 or later
*/
// Prevenir acceso directo al archivo
if (!defined('ABSPATH')) {
exit;
}
// Registrar el shortcode
function register_comments_shortcode() {
add_shortcode('wpse_comments_template', 'render_comments_template');
}
// Función que maneja la lógica del shortcode
function render_comments_template($atts = array(), $content = '') {
if (is_singular() && post_type_supports(get_post_type(), 'comments')) {
ob_start();
comments_template();
add_filter('comments_open', 'wpse_comments_open');
add_filter('get_comments_number', 'wpse_comments_number');
return ob_get_clean();
}
return '';
}
// Inicializar el plugin
add_action('init', 'register_comments_shortcode');
The problem is that this method is very inconvenient, so I looked for a way to create a WordPress plugin that does the same thing. And it's actually very simple:
- you can download it here: my-comments-shortcode.zip
It's a ZIP file containing just these 2 files:
- readme.txt
- my-comments-shortcode.php
How to insert comments in a Brizy template
First, install this plugin in your WordPress. Then, edit the Brizy template you created for blog POSTS (SINGLE mode), and for example, below the box where you indicated the POST content should appear, create another block of type "shortcode" and configure it with this code:
It's that simple. After saving changes, you'll see that WordPress comments now appear in POSTS using that template.
Note: you can work on the format of those comment list elements and the form to add a new comment by rewriting the styles that affect them in your theme's additional CSS. You should already know that Brizy developers recommend using a Blocksy-child as the optimal "host theme" for Brizy.
Añada su comentario: