Make WordPress Core

Opened 11 years ago

Closed 9 years ago

#27156 closed enhancement (wontfix)

add filter to manipulate $before_title and $after_title in widget

Reported by: sireneweb's profile sireneweb Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.1
Component: Widgets Keywords:
Focuses: Cc:

Description

Hi,
actually you can't manipulate correctly the params for before_title and after title, it would be great to add a filter to manipulate them and better if we can specify for which widget based on widget type & location more simplier.

To know the widget_id, you need to print the request with var_dump

Actually i use this :

add_filter ( 'dynamic_sidebar_params' , 'rename_widget_title'); //we use the default priority and 3 arguments in the callback function
function rename_widget_title($params) {
       $widget_request_1 = array('nav_menu-6','nav_menu-2','"nav_menu-5','categories-2');
       $widget_request_2 = array('custom_post_widget-4');
       
        if (in_array($params[0]['widget_id'],$widget_request_1)){
                    $params[0]['before_title'] = '<span class="widgettitle">';
                    $params[0]['after_title'] = '</span>';
        }elseif(in_array($params[0]['widget_id'],$widget_request_2)){
                    $params[0]['before_title'] = '<span class="title_bloc_widget">';
                    $params[0]['after_title'] = '</span>';
        }            
         return $params;
}

Maybe we can display in back office in widget panel the widget id with hover when the mouse is on the title of widget.

Change History (3)

#1 @ocean90
11 years ago

  • Keywords reporter-feedback added
  • Type changed from feature request to enhancement

Hello sireneweb, thanks for your report.

Why do you want to change $before_title and $after_title? Looking at your example your are just changing the class name, probably for styling purposes. A sidebar can also register $before_widget which includes an ID and a class name.

Based on your example something like the following should work too:

.widget-title {
    color: blue;
}

#nav_menu-6 .widget-title,
#nav_menu-2 .widget-title,
#nav_menu-5 .widget-title,
#categories-2 .widget-title {
    color: green;
}

.custom_post_widget .widget-title {
    color: red;
}

#2 @sireneweb
11 years ago

No i don't want change the class, but i want to change the element. Instead of use h2 or h3 i want to change by span for SEO.

Version 0, edited 11 years ago by sireneweb (next)

#3 @chriscct7
9 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

No further requests in 2 years. Closing as wontfix

Note: See TracTickets for help on using tickets.