1. Home
  2. Documentation
  3. Posts Table Pro
  4. Developer documentation
  5. Overriding text strings, labels and messages in the posts table

Overriding text strings, labels and messages in the posts table

All text in Posts Table Pro is fully translatable in the usual way using the gettext functions provided in WordPress. A number of common translations are included in the plugin – see this article for details. You also may be using a translation plugin such as Weglot or WPML.

Regardless of which language is used on your site, you may need to modify some of the text items used in the tables, and we provide several hooks for this purpose.

For example, you may wish to modify the label shown for the search box, or change the ‘Showing 1 of 10 entries’ message below the table.

posts_table_language_defaults

This filter allows you to override the default values for various items of text used within the plugin. You might use this if you want to change the text for a particular item (e.g. the search box label) which has been provided by the plugin in your chosen language.

The example below changes the search box label to ‘Filter’, and also the empty table text.

add_filter( 'posts_table_language_defaults', function( $defaults ) { 
    $defaults['search'] = 'Filter'; 
    $defaults['emptyTable'] = 'Sorry, no articles currently available.'; 
    return $defaults; 
} );

The full list of language strings and their defaults are:

Option Default Description
$defaults['info'] Showing _START_ to _END_ of _TOTAL_ entries. The totals message below the table. _START_, _END_ and _TOTAL_ are placeholders for the post totals which appear in the message.
$defaults['infoEmpty'] Showing 0 entries The totals message when there are no posts.
$defaults['infoFiltered'] (_MAX_ entries in total). The message after the totals when searching/filtering. _MAX_ is the placeholder for the maximum number of posts.
$defaults['lengthMenu'] Show _MENU_ entries. The text for the ‘Show X entries’ dropdown. _MENU_ is the placeholder for the actual dropdown menu.
$defaults['emptyTable'] No data available in table. The message when no posts are found when table is first loaded.
$defaults['zeroRecords'] No matching records found. The message when no posts are found after searching/filtering.
$defaults['search'] Search: The label in front of the search box.
$defaults['searchPlaceholder'] The placeholder text for the search box.
$defaults['paginate']['first'] First The text for the First pagination button (if used).
$defaults['paginate']['last'] Last The text for the Last pagination button (if used).
$defaults['paginate']['next'] Next The text for the Next pagination button (if used).
$defaults['paginate']['previous'] Previous The text for the Previous pagination button (if used).
$defaults['filterBy'] Filter: The label in front of the search filters.
$defaults['resetButton'] Reset The text for the reset button.

posts_table_search_label

This filter is provided for convenience, and is the same as modifying $defaults['search']  when using the posts_table_language_defaults filter.

Allows you to modify the search label shown next to the search box above the table. Defaults to “Search:”. You can set this to an empty string ("") to hide the label.

add_filter( 'posts_table_search_label', function( $label ) {
    return "I'm Looking for:";
} );

posts_table_filter_label

Allows you to change the “Filter:” label shown next to the search filters (if enabled). The posts_table_language_defaults filter will take precedence, if both are used.

add_filter( 'posts_table_filter_label', function( $label ) {
    return "Search by:";
} );

posts_table_search_filter_heading_<column>

Set the default item for the search filter dropdown list. The filter name is dynamic – replace <column> with the relevant column name.

add_filter( 'posts_table_search_filter_heading_categories', function( $heading, Posts_Table_Args $table_args ) { 
   // Do something with terms
   return 'Choose a category';
}, 10, 2 );

posts_table_reset_button

Allows you to change the text used for the Reset button link above the table. The posts_table_language_defaults filter will take precedence, if both are used.

add_filter( 'posts_table_reset_label', function( $label ) {
    return "Clear";
} );

Was this article helpful?

Related Articles