最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

pagination - Modifying the_posts_pagination from within functions.php instead of template files

programmeradmin0浏览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.

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.

Share Improve this question asked Mar 21, 2019 at 10:44 jsmodjsmod 5013 silver badges18 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论