Overview

If your Pager facet is set to display as page numbers, this hook lets you modify the HTML output of the pager links: the numbers, dots, and “Prev”/”Next” links.

Parameters

  • $html | string | The pager link HTML
  • $params | array | An associative array of pager link data (see below)

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

$params = [ 'page' => 5, // The page link number (integer) 'label' => 'Next', // The page link text (string, or integer if it is a number) 'extra_class' => 'last', // The page link extra class: 'first', 'last', 'next', 'prev', 'dots' (string) ];

Usage examples

The following example adds a sr-only class to the last page link:

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

add_filter( 'facetwp_facet_pager_link', function( $html, $params ) { if ( 'last' == $params['extra_class'] ) { $html = str_replace( 'last', 'last sr-only', $html ); } return $html; }, 10, 2 );

The following example removes all links from the pager that are not the “Next” or “Prev” link:

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

add_filter( 'facetwp_facet_pager_link', function( $html ) { if ( ! preg_match('~(prev|next)~', $html) ) { return ''; } return $html; });

Replace the dots

The following example replaces the … dots with dashes:

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

add_filter( 'facetwp_facet_pager_link', function( $html, $params ) { $html = str_replace( '…', '---', $html ); return $html; }, 10, 2 );

The following example replaces the <a> HTML tags of all pager links with <span> tags:

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

add_filter( 'facetwp_facet_pager_link', function( $html ) { return str_replace( [ '<a', '/a>' ], [ '<span', '/span>' ], $html ); });

See also

Last updated: July 1, 2024