Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adjust how Genesis search results are displayed
<?php
/*
Plugin Name: Genesis Search changes
Plugin URI: https://www.damiencarbery.com
Description: Experimenting with changing Genesis search result display.
Author: Damien Carbery
Version: 10.1
Author URI: https://www.damiencarbery.com/
*/
// Disable showing post content in search result content. Later code will show excerpt.
add_action( 'genesis_loop', 'dcwd_search_result_setup' );
function dcwd_search_result_setup() {
if ( is_search() ) {
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
}
}
// Display post/page excerpt in search result content.
add_action( 'genesis_entry_content', 'dcwd_search_result_content' );
function dcwd_search_result_content() {
if ( ! is_search() ) { return; }
the_excerpt();
}
add_action( 'genesis_before_while', 'sk_ul_open' );
/**
* Adds opening unordered list tag above the entries.
*/
function sk_ul_open() {
echo '<ul>';
}
add_filter( 'genesis_markup_entry_open', 'custom_change_open_tag' );
/**
* Changes `article` element for .entry to `li` (opening tag).
*
* @param string $open HTML tag being processed by the API.
* @return string Modified HTML tag.
*/
function custom_change_open_tag( $open ) {
$open = str_replace( '<article', '<li', $open );
return $open;
}
add_filter( 'genesis_markup_entry_close', 'custom_change_close_tag' );
/**
* Changes `article` element for .entry to `li` (closing tag).
*
* @return string Modified HTML tag.
*/
function custom_change_close_tag( $close ) {
$close = str_replace( '</article>', '</li>', $close );
return $close;
}
add_action( 'genesis_after_endwhile', 'sk_ul_close' );
/**
* Adds closing unordered list tag below the entries.
*/
function sk_ul_close() {
echo '</ul>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment