Last edited:

Managing a Blogger-based community involves more than just publishing content, it also requires keeping the environment organized, functional, and safe for everyone. One of the common challenges faced by developers who use custom Blogger themes is handling the Comment Delete Button.

In Blogger’s default system, this feature works automatically behind the scenes. But, once you switch to a custom XML template, things can break. The delete icon may disappear completely, or worse, it might appear for all users even if they can't use it.

This guide will walk you through a proper solution to control the visibility of the delete button so that it only appears for the correct users.

By following this tutorial, your blog will behave according to these rules:

  1. Administrator / Blog Owner: Has access to delete any comment and can see the delete button on all comments.
  2. Logged-in Users (Google Account): Can only see the delete button on comments they personally posted.
  3. Anonymous: Will not see any delete button at all.
Show or Hide Comment Delete Button in Blogger

Understanding How Blogger Handles Comments

Before making any changes, it’s important to understand how Blogger processes comments internally. Blogger uses a system of conditional tags within its XML structure to determine what elements should be displayed to different users. These conditions allow the platform to recognize whether the person viewing the page is the site administrator or the author of a specific comment.

Each comment is stored as a data object, typically referenced as data:comment. This object contains useful information about the comment, including permissions. To control the delete button, we rely on two key properties:

  1. data:comment.adminClass – Returns true when the current viewer is the blog administrator.
  2. data:comment.deleteUrl – Contains the unique URL used to delete a specific comment.

By combining these conditions, we can control exactly when and where the delete button should appear.

IMPORTANT: Always create a backup of your Blogger theme before editing the XML. This allows you to restore your site if something goes wrong during the process.

Method 1: Using CSS

The simplest way to manage the delete button is by using CSS. Blogger already hides certain elements for unauthorized users, particularly those with the class .item-control. If your theme still follows Blogger’s default structure, this method may work immediately.

  1. Go to Theme > Customize > Edit HTML.
  2. Click anywhere inside the code editor and press Ctrl + F.
  3. Search for ]]></b:skin> or </style>.
  4. Just before the closing tag, insert the following CSS:
  5. .item-control{display: none;}

This method is considered non-destructive because it doesn’t alter Blogger’s core logic, it simply hides elements visually. After applying it, test your blog in Incognito mode. The delete buttons should be hidden. When logged in, they should appear only where appropriate.

If this works, you’re done. However, if the delete button is still missing for the admin or visible to everyone, then your theme likely requires deeper customization.

Do not remove this CSS. It is still required even when using the advanced method.

Method 2: Using Blogger XML Data Tags

For heavily customized or modern themes, CSS alone is not enough. In these cases, you need to explicitly define when the delete button should be rendered using Blogger’s XML schema.

Step 1 — Define the Delete Button Structure

Start by locating the delete button component in your theme.

  1. Open the Edit HTML section.
  2. Search for id='commentDeleteIcon'.
  3. If it exists, replace the entire <b:includable> block with the updated version.
  4.  <b:includable id='commentDeleteIcon' var='item'><b:if cond='data:item.deleteUrl'><div expr:class='&quot;item-control &quot; + data:item.adminClass'><svg viewBox="0 0 448 512"><path d="M136.7 5.9L128 32 32 32C14.3 32 0 46.3 0 64S14.3 96 32 96l384 0c17.7 0 32-14.3 32-32s-14.3-32-32-32l-96 0-8.7-26.1C306.9-7.2 294.7-16 280.9-16L167.1-16c-13.8 0-26 8.8-30.4 21.9zM416 144L32 144 53.1 467.1C54.7 492.4 75.7 512 101 512L347 512c25.3 0 46.3-19.6 47.9-44.9L416 144z"/></svg>Delete</a></div></b:if></b:includable>

This updated structure ensures that the delete button only appears when a valid delete URL exists. It also attaches the correct admin class for styling and permissions.

Step 2 — Insert the Button into the Comment Loop

Next, you need to define where the delete button will appear within each comment.

  1. Search for the comment loop, usually written as <b:loop values='data:post.comments' var='comment'>.
  2. Locate the area where the Reply button is displayed.
  3. Insert the include line for the delete button in that section.
  4. <b:include data='comment' name='commentDeleteIcon'/>

This tells Blogger to render the delete icon for each comment based on the defined conditions.

Step 3 — Match the Correct Variable Name

This is one of the most critical steps and a common source of errors. Different themes use different variable names for comments.

For example:

  • If your loop uses var='commentLevel1', you must use that exact name in your include tag.
  • If your loop uses var='cd.level', then your include must also reference cd.level.
  • <b:include data='commentLevel1' name='commentDeleteIcon'/>

If the variable name does not match, Blogger will not recognize the comment data, and the delete button will not appear.

Testing Your Implementation

After saving your changes, it’s important to test everything thoroughly to ensure it works correctly under different conditions.

  1. Admin Test: Log in as the blog owner and check multiple comments. The delete button should appear on all of them.
  2. User Test: Log in with a different Google account and post a comment. You should only see the delete button on your own comment.
  3. Anonymous Test: Open your site in Incognito mode. No delete buttons should be visible.

Testing ensures that permissions are working exactly as intended and prevents potential misuse.

Common Mistakes to Avoid

Even small mistakes can break the functionality of your delete button. Here are some common issues to watch out for:

  • Removing data:comment.deleteUrl: This will completely disable the delete functionality.
  • Skipping Conditional Checks: Without proper <b:if> conditions, the delete button may appear for everyone.
  • Editing the Wrong Section: Make sure you are modifying the correct comment block or includable.
  • Incorrect Variable Names: Always match the loop variable exactly when referencing comment data.

Controlling the visibility of the comment delete button is essential for maintaining a secure and well-managed Blogger community. While Blogger handles this automatically in its default templates, custom themes require manual adjustments to restore proper behavior.

By combining CSS and XML logic, you can ensure that only authorized users have access to the delete function.

Take your time when implementing these changes, double-check your code, and always keep a backup of your theme. Once everything is set up correctly, your comment system will function smoothly.

This is a reminder that if you use our code for a tutorial on your website, please give proper credit to us. Avoid simply copying and pasting the content. We have thoroughly tested the code to ensure it works correctly and is compatible for use on your site.