0

I know that using a function like the following (in functions.php) allows me to customize pagination options:

function custom_theme_pagination(){
    global $wp_query; 
    echo paginate_links();
}

... provided that the theme file then contains <?php custom_theme_pagination(); ?> wherever I want the pagination to show.

However, what I would like to achieve is control how any instance of <?php the_posts_pagination(); ?> will appear without having to create a custom function and then replacing the code in my theme files with <?php custom_theme_pagination(); ?> instead of <?php the_posts_pagination(); ?>.

Is it possible to modify or give arguments for the original <?php the_posts_pagination(); ?> -- in the functions.php file, not in theme files -- without wrapping it in a custom function? If yes, can you explain in detail how that works, please? I ask for details because I want to learn how to do this with pagination and be able to use what I learned for other similar matters that might come up.

Thanks in advance.

1

Is it possible to modify or give arguments for the original -- in the functions.php file, not in theme files -- without wrapping it in a custom function?

No.

There are no hooks that allow modifying the arguments to this function. Wrapping it in your own function is the way to go. There's nothing inherently smarter or superior or more smarter about using filters.

  • So if I am working with a theme that already uses the_posts_pagination and want to customize the arguments, I would have to change all instances of that to my custom pagination function, correct? – jsmod Mar 21 at 11:12
  • 1
    Yes. That's right. Keeping in mind that you should be using a child theme if you intend to modify a theme. – Jacob Peattie Mar 21 at 11:16
  • And from your original answer, if I needed something to change a core function I would have to look and see if "hooks" exist? Otherwise, wrap what I need in a custom function, correct? – jsmod Mar 21 at 11:20
  • 1
    Right. The source for all functions is available at developer.wordpress.org/reference, which you can use to look. You're looking for do_action() and apply_filters(). Make sure to also check the functions that are used by other functions, as sometimes there's filters deeper down. – Jacob Peattie Mar 21 at 11:22
  • Great, thank you for the link :) I think I was looking at the wrong documentation or an old one. – jsmod Mar 21 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.