Remove Widget Title Conditionally

Arshad
9 Aug 2022

If you want to remove the widget title conditionally just use the below code-snippet.

I’m using Scripts Organizer to add it, you can also do it via any Code Snippet or functions.php if you are using a theme.

Steps to use it in Scripts Organizer :

  1. Add a new code block, Set Trigger Location to EVERYWHERE, and Script Location to PHP.
  2. paste the below code.
  3. Publish.
  4. Whenever you want to hide the title of specific widget, just put a ! (Exclamation Mark) in the beginning of Title, in other words prefix !
<?php
// REMOVE WIDGET TITLE IF IT BEGINS WITH EXCLAMATION POINT
add_filter('widget_title', 'remove_widget_title');
function remove_widget_title($widget_title)
{
    if (substr($widget_title, 0, 1) == '!') {
        return;
    } else {
        return ($widget_title);
    }
}

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy