Category: Notes

  • Re-centre FacetWP map after interaction

    Useful if the FacetWP map is initially hidden on page load and is only shown after some interaction, meaning that the map markers map be shown but too zoomed out otherwise.

    $('.map-toggle').on('click', function(e) {
        // Apply fitBounds to the Google Map so all markers fit...
        FWP_MAP.map.fitBounds(FWP_MAP.bounds);
    
        e.preventDefault();
    });
  • Disable lazyload on WordPress image

    <?php
    the_post_thumbnail( '', array( 'loading' => 'eager' ) );
  • Allow two character words in SearchWP results

    Useful if there’s a commonly used abbreviation on the website e.g. UT, that wouldn’t otherwise be returned in SearchWP results (default word length is three).

    <?php
    
    /**
     * Reduce SearchWP's minimum character length to 2 (default is 3).
     *
     * @url https://searchwp.com/documentation/hooks/searchwp-tokens-minimum_length/
     */
    add_filter( 'searchwp\tokens\minimum_length', function ( $min ) {
    	return 2;
    } );
  • Make WordPress next / previous blog pagination buttons have left / right alignment

    <div class="blog-navigation"><?php posts_nav_link( ' ', 'Previous', 'Next' ); ?></div>
    .blog-navigation {
    	display: flex;
    	justify-content: flex-start;
    	padding: 1rem 0;
    
    	a {
    		@extend .button;
    		@extend .button--primary;
    	}
    
    	// Ensures Next button is always right aligned, even when no Previous button
    	a:last-of-type {
    		margin-left: auto;
    	}
    }
  • Only output HTML for a WordPress menu location, if a menu is set for that location

    Otherwise it falls back to echoing another menu (the first?) instead of nothing.

    <?= wp_nav_menu( [ 'echo' => false, 'fallback_cb' => false, 'theme_location' => 'footer-2-a' ] ) ?: ''; ?>