Skip to content

Instantly share code, notes, and snippets.

@sabrina-zeidan
Created September 6, 2020 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sabrina-zeidan/b27923623fc2839e8c401a14043e266b to your computer and use it in GitHub Desktop.
Save sabrina-zeidan/b27923623fc2839e8c401a14043e266b to your computer and use it in GitHub Desktop.
Html wrapper for WP_Query (insert text before or after the loop)
<?php
//Handy when CPT previews are used in different templates across the site
add_action( 'loop_start', 'recipes_loop_start' );
function recipes_loop_start( $query ){
if ( !$query->is_main_query() && $query->get('post_type')== 'recipe' && !is_admin()) echo "<ul class='recipes-preview'>";
}
add_action( 'loop_end', 'recipes_loop_end' );
function recipes_loop_end( $query ){
if ( !$query->is_main_query() && $query->get('post_type')== 'recipe' && !is_admin()) echo "</ul>";
}a
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment