Instantly share code, notes, and snippets.

generatepress

View GitHub Profile
@generatepress
generatepress / gist:9fe556128433b11114b489406fc8dee4
Created Feb 14, 2019
Disable the Header Element if there isn't a featured image.
View gist:9fe556128433b11114b489406fc8dee4
add_filter( 'generate_header_element_display', function( $display ) {
if ( ! has_post_thumbnail() ) {
return false;
}
return $display;
} );
@generatepress
generatepress / gist:18a46cb723eb8f1bb198d620b8d36814
Created Feb 13, 2019
Choose which post types you're entry meta displays on. Wrapped in after_setup_theme to fire later.
View gist:18a46cb723eb8f1bb198d620b8d36814
add_action( 'after_setup_theme', function() {
add_filter( 'generate_entry_meta_post_types', function( $types ) {
$types[] = 'my-post-type';
$types[] = 'recipes';
return $types;
} );
} );
@generatepress
generatepress / gist:a5f0dfd0db3c1d7fc5b217e07203fc58
Last active Nov 5, 2018
Remove screen reader text from more link in the feed
View gist:a5f0dfd0db3c1d7fc5b217e07203fc58
add_filter( 'generate_excerpt_more_output', function( $more ) {
if ( is_feed() ) {
return sprintf( ' ... <a title="%1$s" class="read-more" href="%2$s">%3$s</a>',
the_title_attribute( 'echo=0' ),
esc_url( get_permalink( get_the_ID() ) ),
__( 'Read more', 'generatepress' )
);
}
return $more;
@generatepress
generatepress / smooth-scroll.min.js
Created Oct 19, 2018
Potential fix for smooth scroll on mobile
View smooth-scroll.min.js
window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;0<=--t&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),function(){if("function"==typeof window.CustomEvent)return;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}e.prototype=window.Event.prototype,window.CustomEvent=e}(),function(){for(var a=0,e=["ms","moz","webkit","o"],t=0;t<e.length&&!window.requestAnimationFrame;++t)window.requestAnimationFrame=window[e[t]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[e[t]+"CancelAnimationFrame"]||window[e[t]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(e,t){var n=(new Date).getTime(),o=Math.max(0,16-(n-a)),i=window.setTimeout(function(){e(n+o)},o);return a=n+o,i}),window.cancelAnimationFrame||(window.cance
@generatepress
generatepress / comments.php
Last active Oct 3, 2018
Move the comment form above the comments.
View comments.php
<?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
View gist:ba6e3febda3b856b8c3ac29fd5054ce6
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
@generatepress
generatepress / gist:d52d96cf98522b815fcde4892b573d0e
Last active Sep 30, 2018
Add number of items in cart to WooCommerce menu item
View gist:d52d96cf98522b815fcde4892b573d0e
function custom_wc_cart_link() {
ob_start();
?>
<a href="<?php echo esc_url( wc_get_cart_url() ); ?>" class="cart-contents">
<?php echo sprintf ( _n( '%d', '%d', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?>
<span class="amount"><?php echo wp_kses_data( WC()->cart->get_cart_subtotal() ); ?></span>
</a>
<?php
return ob_get_clean();
}
@generatepress
generatepress / gist:6a9ad4e007ae0a7388bbbbb7b3ae068f
Last active Sep 18, 2018
Remove meta links from comments.
View gist:6a9ad4e007ae0a7388bbbbb7b3ae068f
if ( ! function_exists( 'generate_comment' ) ) {
/**
* Template for comments and pingbacks.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*/
function generate_comment( $comment, $args, $depth ) {
$args['avatar_size'] = apply_filters( 'generate_comment_avatar_size', 50 );
if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?>
@generatepress
generatepress / gist:53add6a3115a586e06004a6d453cf8b6
Created Aug 31, 2018
Code causing conflict with Beaver Themer
View gist:53add6a3115a586e06004a6d453cf8b6
add_action( 'woocommerce_before_shop_loop', 'generatepress_wc_before_shop_loop' );
/**
* Add opening element inside shop page.
*
* @since 1.3
*/
function generatepress_wc_before_shop_loop() {
$classes = apply_filters( 'generate_woocommerce_container_classes', array(
'wc-columns-' . generatepress_wc_get_setting( 'columns' ),
//'wc-tablet-columns-' . generatepress_wc_get_setting( 'tablet_columns' ),
@generatepress
generatepress / gist:fae398a39bb8802364e623836941eab4
Created Aug 16, 2018
Apply the GPP smooth scroll to all hash links.
View gist:fae398a39bb8802364e623836941eab4
add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
$elements[] = 'a[href*="#"]';
return $elements;
} );