Skip to content

Instantly share code, notes, and snippets.

@generatepress
generatepress / gist:e125229c3884b769c25b5546d8dd735e
Created May 4, 2018 04:35
Remove the GP Dashboard for non super admins
add_filter( 'generate_dashboard_page_capability', 'tu_super_admin_dashboard' );
function tu_super_admin_dashboard() {
return 'manage_sites';
}
@generatepress
generatepress / gist:57610006a85c206fea53131986022a91
Last active April 29, 2018 15:47
Try new WC secondary image function
function generatepress_wc_secondary_product_image() {
$post_type = get_post_type( get_the_ID() );
if ( 'product' == $post_type && method_exists( 'WC_Product', 'get_gallery_image_ids' ) ) {
$product = new WC_Product( get_the_ID() );
$attachment_ids = $product->get_gallery_image_ids();
if ( $attachment_ids && generatepress_wc_get_setting( 'product_secondary_image' ) && generatepress_wc_get_setting( 'product_archive_image' ) && has_post_thumbnail() ) {
$secondary_image_id = $attachment_ids['0'];
echo wp_get_attachment_image( $secondary_image_id, 'shop_catalog', '', $attr = array( 'class' => 'secondary-image attachment-shop-catalog' ) );
@generatepress
generatepress / gist:92ebb34e67ce6f538fdb457137f7a9b4
Created April 29, 2018 04:04
Add categories, tags and comments link to top meta
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' );
add_filter( 'generate_show_comments', '__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 / functions.php
Created April 16, 2018 16:49
Set archives to full width if using Elementor Themer.
add_action( 'wp', function() {
add_filter( 'body_class', function( $classes ) {
if ( function_exists( 'elementor_location_exits' ) && elementor_location_exits( 'archive', true ) ) {
$classes[] = 'full-width-content';
}
return $classes;
} );
} );
@generatepress
generatepress / gist:71df96fd4ecaad5ffafa46e347cee294
Last active March 10, 2018 07:53
Integrate LifterLMS layouts into GP
function tu_lifterlms_start() { ?>
<div id="primary" <?php generate_content_class();?>>
<main id="main" <?php generate_main_class(); ?>>
<?php do_action('generate_before_main_content'); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php generate_article_schema( 'CreativeWork' ); ?>>
<div class="inside-article">
<?php do_action( 'generate_before_content'); ?>
<div class="entry-content" itemprop="text">
<?php
}
add_action( 'generate_before_header', 'tu_add_gtm_code', 0 );
function tu_add_gtm_code() {
if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) {
gtm4wp_the_gtm_tag();
}
}
@generatepress
generatepress / sidebar.php
Last active March 15, 2018 15:14
Different right sidebar for pages.
<?php
/**
* The Sidebar containing the main widget areas.
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
@generatepress
generatepress / gist:8b1bb2d303ec2a8cc73fb382fd3656a6
Created February 11, 2018 05:24
Move categories and tags next to date and author
add_filter( 'generate_post_author_output', 'tu_add_tags_to_author' );
add_filter( 'generate_show_categories', '__return_false' );
add_filter( 'generate_show_tags', '__return_false' );
function tu_add_tags_to_author( $output ) {
$tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
$tags = '';
if ( $tags_list ) {
$tags = sprintf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
_x( 'Tags', 'Used before tag names.', 'generatepress' ),
@generatepress
generatepress / gist:38a3d4d0e3f1be118cac76937e4c92e6
Last active September 23, 2019 17:05
Move navigation search to the secondary navigation
add_action( 'after_setup_theme', function() {
remove_action( 'generate_inside_navigation', 'generate_navigation_search' );
remove_action( 'generate_inside_navigation', 'generate_mobile_menu_search_icon' );
add_action( 'generate_inside_secondary_navigation', 'generate_navigation_search' );
add_action( 'generate_inside_secondary_navigation', 'generate_mobile_menu_search_icon' );
remove_filter( 'wp_nav_menu_items', 'generate_menu_search_icon', 10, 2 );
} );
@generatepress
generatepress / gist:803a950d6381dd98e6bc4418b817ed82
Created January 30, 2018 03:13
Exclude categories from single post pagination
if ( ! function_exists( 'generate_content_nav' ) ) {
/**
* Display navigation to next/previous pages when applicable.
*
* @since 0.1
*
* @param string $nav_id The id of our navigation.
*/
function generate_content_nav( $nav_id ) {
if ( ! apply_filters( 'generate_show_post_navigation', true ) ) {