Opened 13 years ago
Last modified 2 years ago
#19272 assigned enhancement
Add Filter to Nav Menu Support Themes Text
Reported by: | wpsmith | Owned by: | bhargavbhandari90 |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | trivial | Version: | |
Component: | Menus | Keywords: | good-first-bug has-patch needs-docs dev-feedback |
Focuses: | Cc: |
Description (last modified by )
Frameworks could use a filter here to customize the message: _n('Your theme supports %s menu. Select which menu you would like to use.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations )
. For example, it may be the child theme that doesn't support the menus. Also, if none are supported (say via add_theme_support), then when it's zero, it says: "Your theme supports 0 menus. Select which menu appears in each location." (which doesn't make much sense). So adding a filter can enable theme developers to further customize.
An example use case:
add_filter( 'nav_menu_theme_support_text' , 'wps_nav_menu_theme_support_text' ); function wps_nav_menu_theme_support_text ( $num_locations ) { if ( $num_locations == 0 ) $text = 'Your child theme does not support custom menus.'; else $text = _n('Your theme supports %s menu. Select which menu you would like to use.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ); return $text; }
Attachments (3)
Change History (21)
#4
in reply to:
↑ description
@
10 years ago
Replying to wpsmith:
Frameworks could use a filter here to customize the message: _n('Your theme supports %s menu. Select which menu you would like to use.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ). For example, it may be the child theme that doesn't support the menus. Also, if none are supported (say via add_theme_support), then when it's zero, it says: "Your theme supports 0 menus. Select which menu appears in each location." (which doesn't make much sense). So adding a filter can enable theme developers to further customize.
An example use case:
add_filter( 'nav_menu_theme_support_text' , 'wps_nav_menu_theme_support_text' );
function wps_nav_menu_theme_support_text ( $num_locations ) {
if ( $num_locations == 0 )
$text = 'Your child theme does not support custom menus.';
else
$text = _n('Your theme supports %s menu. Select which menu you would like to use.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations );
return $text;
}
As we are applying filters to string, so add filter will contain two arguments so $num_locations should be 2nd argument..
#6
@
9 years ago
- Keywords needs-docs added; needs-testing removed
- Owner changed from bhargavbhandari90 to DrewAPicture
#8
@
9 years ago
- Keywords dev-feedback added; good-first-patch removed
As of [31951] we're using the decoupled strings from the Customizer here, which actually means we're using one of two different strings. @SergeyBiryukov: What would be your best suggestion if we wanted to make this text filterable? My first thought was to package them into an array and make that filterable, but I'm not sure I like that.
Currently:
<?php if ( 1 == $num_locations ) { echo '<p>' . __( 'Your theme supports one menu. Select which menu you would like to use.' ) . '</p>'; } else { echo '<p>' . sprintf( _n( 'Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) ) . '</p>'; }
#9
@
9 years ago
- Milestone changed from 4.4 to Future Release
Moving off the milestone until we can figure out a plan here.
This ticket was mentioned in Slack in #docs by morganestes. View the logs.
8 years ago
#12
@
7 years ago
- Owner set to bhargavbhandari90
Assigning ownership to mark the good-first-bug
as "claimed".
This ticket was mentioned in Slack in #core by sergey. View the logs.
3 years ago
This ticket was mentioned in PR #2929 on WordPress/wordpress-develop by whaze.
2 years ago
#16
- Keywords needs-refresh removed
Trac ticket: https://core.trac.wordpress.org/ticket/19272
This ticket was mentioned in PR #2930 on WordPress/wordpress-develop by samykantari.
2 years ago
#17
Trac ticket: https://core.trac.wordpress.org/ticket/19272
This ticket was mentioned in PR #2931 on WordPress/wordpress-develop by maxpertici.
2 years ago
#18
Add a filter nav_menu_theme_support_text
Trac ticket: https://core.trac.wordpress.org/ticket/19272
Needs to be refreshed because of #24945