Skip to content

Instantly share code, notes, and snippets.

@generatepress
generatepress / gist:a6d9d71218832f0f0260885f9f5acd4f
Created January 21, 2018 18:08
Remove the header on all single product pages.
add_action( 'wp', 'tu_remove_header_from_products' );
function tu_remove_header_from_products() {
if ( is_singular( 'product' ) ) {
remove_action( 'generate_header', 'generate_construct_header' );
}
}
@generatepress
generatepress / gist:c0fbec9e017e6f148d8d644be90a6fed
Created November 30, 2017 03:41
Set a default image background in the Page Header
add_filter( 'generate_page_header_options', 'tu_default_featured_image' );
function tu_default_featured_image( $options ) {
if ( '' == $options['image_id'] ) {
$options['image_id'] = 4667;
}
return $options;
}
@generatepress
generatepress / gist:d25cdc125c7950bffc7223daaeea3065
Created October 20, 2017 19:53
Move the navigation below the page header
add_action( 'wp','tu_move_nav_after_page_header' );
function tu_move_nav_after_page_header() {
if ( ! function_exists( 'generate_page_header_get_options' ) ) {
return;
}
$options = generate_page_header_get_options();
if ( '' !== $options['content'] ) {
remove_action( 'generate_after_header', 'generate_add_navigation_after_header', 5 );
@generatepress
generatepress / gist:cdb67600504b71169c285c9d1788d5d7
Last active August 27, 2017 00:26
Show Gridable Add Row button in Sections
add_action( 'admin_head', 'tu_show_gridable_button_sections' );
function tu_show_gridable_button_sections() {
?>
<style>
#wp-generate-sections-editor-wrap .wp-media-buttons > .gridable-insert-row-button {
display: inline-block;
}
</style>
<?php
}
@generatepress
generatepress / gist:8bc94ae43f67c40a077aefc8ec970fd0
Last active January 23, 2019 07:09
Show date as: Published on {date} at {time} | Updated on {date} at {time}
add_filter( 'generate_post_date_output', 'tu_show_modified_date' );
function tu_show_modified_date() {
$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 = 'Updated on: <time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
@generatepress
generatepress / gist:b3c574437f49c1fd26f4d6e9a3a6af55
Created August 15, 2017 07:12
Add categories and tags after the author
add_filter( 'generate_post_author_output', 'tu_categories_to_author' );
add_filter( 'generate_category_list_output', '__return_false' );
add_filter( 'generate_tag_list_output', '__return_false' );
function tu_categories_to_author( $output ) {
$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
$categories_list = sprintf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
_x( 'Categories', 'Used before category names.', 'generatepress' ),
$categories_list
);
@generatepress
generatepress / gist:4a6ec717cdb740066b1a1cfb59e9bccb
Created August 9, 2017 06:41
Append an edit link after the author
add_filter( 'generate_post_author_output','tu_append_edit_posts_link' );
function tu_append_edit_posts_link( $output ) {
global $post;
if ( current_user_can( 'edit_post', $post->ID ) ) {
$url = get_edit_post_link();
return $output . ' | <a href="' . esc_url( $url ) . '">Edit</a>';
} else {
return $output;
}
}
@generatepress
generatepress / gist:ca10c4de1a66615d8cdc9b3ad021f95b
Created July 25, 2017 21:44
Show excerpts when using the image post format
add_filter( 'generate_show_excerpt', 'tu_excerpt_image_format' );
function tu_excerpt_image_format( $excerpt ) {
if ( 'image' == get_post_format() ) {
return true;
}
return $excerpt;
}
@generatepress
generatepress / gist:70a67d226b9954cc4945ada391ba215b
Created July 22, 2017 06:37
Add Alef into the Google fonts list
add_filter( 'generate_typography_customize_list','tu_add_google_fonts' );
function tu_add_google_fonts( $fonts ) {
$fonts[ 'alef' ] = array( 'name' => 'Alef' );
return $fonts;
}
@generatepress
generatepress / gist:687f18772343314b05828725253db342
Created July 20, 2017 16:01
Remove sidebars and footer widgets on 404 page
add_filter( 'generate_sidebar_layout', 'tu_remove_sidebars' );
function tu_remove_sidebars( $sidebar ) {
if ( is_404() ) {
return 'no-sidebar';
}
return $sidebar;
}
add_filter( 'generate_footer_widgets', 'tu_remove_footer_widgets' );