Conditional based on the current page number in a paginated WordPress Archive

You may want to display something conditionally on one specific page of a paginated archive, but not on any other pages. There is not currently a built-in shortcode available to give you access to the current page number in a paginated archive, so you can use this custom shortcode instead. Add the following code to your child theme’s functions.php file:

add_shortcode( 'get_archive_pg_num', 'get_archive_pg_num_func');
function get_archive_pg_num_func($atts)
{
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  return $paged;
}

Then register ‘get_archive_pg_num’ in Toolset > Settings > 3rd Party Shortcode Arguments so you can use it in a conditional. Then you can use a conditional like this to test if the current page is page 1:

[wpv-conditional if="([get_archive_pg_num] eq '1')"]
This is page one
[/wpv-conditional]

This custom shortcode was shared in the forum here:
https://wp-types.com/forums/topic/conditional-if-to-output-a-text-at-first-page-of-archive/


Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments