/** * High-performance category gallery setup * Limits posts, avoids expensive loops, works with gridsby gallery template */ add_action( 'pre_get_posts', function( $query ) { // Only modify main query on front-end category pages if ( $query->is_main_query() && !is_admin() && $query->is_category() ) { // 1. Limit number of posts per category $num = intval( get_theme_mod('gridsby_category_num_posts') ); if ( !$num || $num < 1 ) $num = 12; // default 12 $query->set( 'posts_per_page', $num ); // 2. Disable expensive WordPress features for speed $query->set('no_found_rows', true); // disables COUNT(*) for pagination $query->set('update_post_meta_cache', false); $query->set('update_post_term_cache', false); // 3. Optional: only load 'image' post formats for gallery view $query->set( 'tax_query', array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-image'), 'operator' => 'IN', ), ) ); } }); /** * Choose gallery template efficiently */ add_filter( 'template_include', function( $template ) { if ( is_category() || is_tag() ) { // Lightweight check: does category contain only 'image' posts? $image_only = ! ( new WP_Query(array( 'cat' => get_queried_object_id(), 'posts_per_page' => 1, 'post_type' => 'post', 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-image'), 'operator' => 'NOT IN', ) ) )) )->have_posts(); if ( $image_only ) { $template = get_query_template( 'archive-image' ); } } return $template; }); /** * Load gallery scripts/styles for category pages efficiently */ add_action( 'wp_enqueue_scripts', function() { if ( is_category() || is_tag() ) { // Only enqueue scripts if gallery view is active $image_only = ! ( new WP_Query(array( 'cat' => get_queried_object_id(), 'posts_per_page' => 1, 'post_type' => 'post', 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-image'), 'operator' => 'NOT IN', ) ) )) )->have_posts(); if ( $image_only ) { wp_enqueue_style( 'gridsby-grid-css', get_template_directory_uri() . '/css/grid.css' ); wp_enqueue_script( 'gridsby-grid3d', get_template_directory_uri() . '/js/grid3d.js', array(), false, true ); wp_enqueue_script( 'gridsby-masonry', get_template_directory_uri() . '/js/masonry.pkgd.js', array(), false, true ); wp_enqueue_script( 'gridsby-gridsby-gallery', get_template_directory_uri() . '/js/gridsby-gallery.js', array(), false, true ); } } });
Call to undefined function html_tag_schema()