Skip to content

Instantly share code, notes, and snippets.

@generatepress
generatepress / gist:35c505f1aac124edf071f9008061ee6d
Created August 6, 2020 15:37
Don't close off-canvas panel on menu item click
<script>
var slideoutLinks = document.querySelectorAll( '.slideout-navigation ul a' );
for ( var i = 0; i < slideoutLinks.length; i++ ) {
slideoutLinks[i].removeEventListener( 'click', closeOffsideOnAction, false );
};
</script>
function generateblocks_get_parsed_content( $content = '' ) {
if ( ! function_exists( 'has_blocks' ) ) {
return;
}
if ( ! $content && has_blocks( get_the_ID() ) ) {
global $post;
if ( ! is_object( $post ) ) {
return;
add_filter( 'generate_premium_url_args', function( $args ) {
$args['ref'] = 123; // Add your affiliate ID
return $args;
} );
@generatepress
generatepress / gist:565683b10cca65050d7fb3a006efbc29
Created July 19, 2019 00:57
Add search button with icon to the navigation search
add_filter( 'generate_navigation_search_output', function() {
printf(
'<form method="get" class="search-form navigation-search" action="%1$s">
<input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
<input type="submit" class="search-button" value="&#xf002;">
</form>',
esc_url( home_url( '/' ) ),
esc_attr( get_search_query() ),
esc_attr_x( 'Search', 'label', 'generatepress' )
);
@generatepress
generatepress / gist:2bb2667c9413e29579288687add966de
Created July 18, 2019 17:26
Integrate the Custom Fonts (https://wordpress.org/plugins/custom-fonts/) plugin with the GP Customizer.
add_filter( 'generate_typography_default_fonts', function( $fonts ) {
if ( ! class_exists( 'Bsf_Custom_Fonts_Taxonomy' ) ) {
return $fonts;
}
$all_fonts = Bsf_Custom_Fonts_Taxonomy::get_fonts();
if ( ! empty( $all_fonts ) ) {
foreach ( $all_fonts as $font_family_name => $fonts_url ) {
$fonts[] = $font_family_name;
@generatepress
generatepress / comments.php
Created July 18, 2019 16:31
Move comment form above list of comments.
<?php
/**
* The template for displaying Comments.
*
* The area of the page that contains both current comments
* and the comment form. The actual display of comments is
* handled by a callback to generate_comment() which is
* located in the inc/template-tags.php file.
*
* @package GeneratePress
@generatepress
generatepress / gist:64ee0304f3fd166f02df341fc9cc0968
Created July 2, 2019 01:25
Adding a search icon to the GP search form button
add_filter( 'generate_search_button', function() {
return '&#xf002;';
} );
@generatepress
generatepress / gist:179434f97888af190ee1d65e36402962
Created May 5, 2019 16:16
Make Dispatch Custom Post Navigation work with any custom post type
<div id="post-nav">
<?php global $post;
$prevPost = get_previous_post(false);
$post_type = get_post_type();
if($prevPost) {
$args = array(
'posts_per_page' => 1,
'include' => $prevPost->ID,
'post_type' => $post_type,
@generatepress
generatepress / gist:bb5b5b84350f725ba3deaf5ee126c4cc
Created March 27, 2019 21:01
Filter logo URL when using Polylang
add_filter( 'generate_logo_href', function( $url ) {
if ( function_exists( 'pll_home_url' ) ) {
return pll_home_url();
}
return $url;
} );
@generatepress
generatepress / gist:4f76e08e7198841bef15f9347afe7454
Created March 26, 2019 14:42
Don't show Elements if Polylang language doesn't match
function generate_elements_ignore_languages( $post_id ) {
if ( function_exists( 'pll_get_post_language' ) && function_exists( 'pll_current_language' ) ) {
$language = pll_get_post_language( $post_id, 'locale' );
if ( $language && $language !== pll_current_language( 'locale' ) ) {
return false;
}
}
return $post_id;