Skip to content

Instantly share code, notes, and snippets.

@generatepress
generatepress / gist:b66e008efdf664c1ca9a9e24d36e2feb
Created July 15, 2017 06:53
Lightweight grid columns example
[lgc_column grid="33" tablet_grid="33" mobile_grid="100"]First column content in here[/lgc_column]
[lgc_column grid="33" tablet_grid="33" mobile_grid="100"]Second column content in here[/lgc_column]
[lgc_column grid="33" tablet_grid="33" mobile_grid="100" last="true"]Third column content in here[/lgc_column]
@generatepress
generatepress / gist:4b79c032a29e52f769eb3a1e7d41155f
Created July 7, 2017 04:18
Disable the title, top bar and header on pages and products.
add_action( 'wp', 'tu_disable_cpt_elements' );
function tu_disable_cpt_elements() {
if ( is_page() || 'product' == get_post_type() ) {
remove_action( 'generate_before_header', 'generate_top_bar', 5 );
remove_action( 'generate_header', 'generate_construct_header' );
add_filter( 'generate_show_title', '__return_false' );
}
}
@generatepress
generatepress / gist:a5a842677e75ef968aa52ee4d9e805a3
Created June 28, 2017 22:00
Search string for {{custom_field}} and return the post meta
if ( strpos( $content, '{{custom_field' ) !== false ) {
$data = preg_match_all('/{{custom_field="([^"]*)"}}/', $content, $matches);
foreach ( $matches[1] as $match ) {
if ( null !== get_post_meta( get_the_ID(), $match, true ) && '' !== get_post_meta( get_the_ID(), $match, true ) ) {
$search[] = '{{custom_field="' . $match . '"}}';
$replace[] = get_post_meta( get_the_ID(), $match, true );
}
}
}
@generatepress
generatepress / gist:3483a8fd6b46aa2d3f6e4ee090c7db58
Created June 23, 2017 16:31
Add a Google font to the request to Google
add_filter( 'generate_typography_google_fonts', 'tu_add_google_font_request' );
function tu_add_google_font_request( $fonts ) {
return $fonts . '|Amatic+SC';
}
@generatepress
generatepress / gist:445e1430db638b6ce4f3ddfb4c2ca9cf
Created June 14, 2017 21:00
Set Elementor pages to full width with no title automatically
add_action( 'template_redirect','tu_add_elementor_filter', 999 );
function tu_add_elementor_filter() {
if ( in_array( 'elementor-page elementor-page-' . get_the_ID(), get_body_class() ) ) {
add_filter( 'body_class', 'tu_add_elementor_classes' );
add_filter( 'generate_show_title','__return_false' );
}
}
function tu_add_elementor_classes( $classes ) {
$classes[] = 'full-width-content';
@generatepress
generatepress / gist:ad921185bc15b6f28bcf773596217739
Created June 14, 2017 20:40
Set the page builder container to full width if Beaver Builder is active
add_filter( 'body_class', 'tu_bb_full_width_class' );
function tu_bb_full_width_class( $classes ) {
if ( class_exists( 'FLBuilderModel' ) && FLBuilderModel::is_builder_enabled() ) {
$classes[] = 'full-width-content';
return $classes;
}
}
@generatepress
generatepress / gist:14851417f7bcc7620737e2e22d2c2f98
Created May 25, 2017 07:32
Add alt tag to featured images
add_filter('wp_get_attachment_image_attributes','tu_featured_image_alt', 10, 2);
function tu_featured_image_alt( $attr, $attachment ) {
remove_filter('wp_get_attachment_image_attributes','tu_featured_image_alt');
$attr['alt'] = $attachment->post_title;
return $attr;
}
@generatepress
generatepress / gist:a6352f8ff0e6fb19453a5008f5d579e0
Created May 18, 2017 06:38
Remove single next/prev post links
if ( ! function_exists( 'generate_content_nav' ) ) :
/**
* Display navigation to next/previous pages when applicable
*/
function generate_content_nav( $nav_id ) {
global $wp_query, $post;
// Don't print empty markup in archives if there's only one page.
if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) ) {
@generatepress
generatepress / gist:3cdc5dabe0f19b93ed692142aa50a576
Created May 3, 2017 04:04
Get beta updates in your Dashboard using GP Premium 1.3-beta1 and greater
add_action( 'after_setup_theme','tu_beta_tester' );
function tu_beta_tester() {
add_filter( 'generate_premium_beta_tester','__return_true' );
}
@generatepress
generatepress / gist:a15f0cb00c90f218d04d802c0178bf5c
Created May 2, 2017 15:39
Remove GeneratePress menu in Dashboard
add_action( 'after_setup_theme','tu_remove_gp_admin_menu' );
function tu_remove_gp_admin_menu() {
remove_action('admin_menu', 'generate_create_menu');
}