How to edit or override a Core function?

There is no filter, but you can set the type argument to array when you call paginate_links(), and then you can run a filter on the returned array.

Example:

$links = array_map(
    function( $link ) {
        if ( FALSE === strpos( $link, '/page/' ) )
            return str_replace( '<a ', '<a data-page="1" ', $link );

        return preg_replace(
            '~<a (.*)/page/(\d+)~',
            '<a data-page="\\2" \\1/page/\\2',
            $link
        );
    },
    paginate_links( [ 'type' => 'array' ] )
);

print join( ' | ', $links );

Leave a Comment