Skip to content

Instantly share code, notes, and snippets.

@generatepress
generatepress / searchform.php
Created March 19, 2019 02:57
Fixed searchform.php. To be fixed in GP 2.3
<?php
/**
* The template for displaying search forms in Generate
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
@generatepress
generatepress / attachment.php
Created March 16, 2019 16:49
Example of attachment.php
<?php
/**
* The Template for displaying all single posts.
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
@generatepress
generatepress / gist:9fe556128433b11114b489406fc8dee4
Created February 14, 2019 22:36
Disable the Header Element if there isn't a featured image.
add_filter( 'generate_header_element_display', function( $display ) {
if ( ! has_post_thumbnail() ) {
return false;
}
return $display;
} );
@generatepress
generatepress / gist:18a46cb723eb8f1bb198d620b8d36814
Created February 13, 2019 04:05
Choose which post types you're entry meta displays on. Wrapped in after_setup_theme to fire later.
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 November 5, 2018 23:29
Remove screen reader text from more link in the feed
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 October 19, 2018 20:43
Potential fix for smooth scroll on mobile
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 April 22, 2020 23:31
Move the comment form above the 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:ba6e3febda3b856b8c3ac29fd5054ce6
Created September 30, 2018 01:43
Show only the updated date if set
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 September 30, 2018 16:28
Add number of items in cart to WooCommerce menu item
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 September 18, 2018 16:53
Remove meta links from comments.
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 ) : ?>