Last active
August 25, 2023 13:21
-
-
Save zephyrmike/2cc4f8d463a0358faeb14869acf41949 to your computer and use it in GitHub Desktop.
PHP snippets for GeneretePress and GenerateBlocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dynamic titles for search results | |
// use shortcode [search_title] | |
add_shortcode('search_title',function(){ | |
return sprintf( | |
/* translators: 1: Search query name */ | |
__( 'Search Results for: %s', 'generatepress' ), | |
'<span class="search-query">' . get_search_query() . '</span>' | |
); | |
}); | |
// dynamic titles for search results AND archives | |
// use shortcode [multi_title] | |
add_shortcode('multi_title', 'get_custom_title' ); | |
function get_custom_title() { | |
if ( is_search() ) { | |
return 'Search results for: ' . get_search_query(); | |
} elseif ( is_archive() ) { | |
return get_the_archive_title(); | |
} | |
} | |
// remove pages from search results | |
function exclude_pages_from_search( $query ) { | |
if ( $query->is_search() && $query->is_main_query() && ! is_admin() ) { | |
$query->set( 'post_type', 'post' ); | |
} | |
} | |
add_filter( 'pre_get_posts','exclude_pages_from_search' ); | |
// view customizer additional css in the WP editor | |
add_filter( 'block_editor_settings_all', function( $editor_settings ) { | |
$css = wp_get_custom_css_post()->post_content; | |
$editor_settings['styles'][] = array( 'css' => $css ); | |
return $editor_settings; | |
} ); | |
// view child theme css in the WP editor | |
add_filter( 'generate_editor_styles', function( $editor_styles ) { | |
$editor_styles[] = 'style.css'; | |
return $editor_styles; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment