Skip to content

Instantly share code, notes, and snippets.

@marklchaves
Last active April 5, 2020 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marklchaves/c6ba6335ca634014ffb416db46f79b05 to your computer and use it in GitHub Desktop.
Save marklchaves/c6ba6335ca634014ffb416db46f79b05 to your computer and use it in GitHub Desktop.
Using GeneratePress Built-in Hooks for Customising how Individual Blog Posts are Layed Out on a Blog Index or Homepage
<?php
/**
* GeneratePress child theme functions and definitions.
*
* Add your custom PHP in this file.
* Only edit this file if you have direct access to it on your server (to fix errors if they happen).
*/
function generatepress_child_enqueue_scripts() {
if ( is_rtl() ) {
wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' );
}
}
add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );
/**
* Custom Actions and Filters
*/
// Move the date above the title.
function add_date_above_title() {
echo '<div class="date-wrapper">' . the_date() . '</div>';
}
add_action( 'generate_before_entry_title', 'add_date_above_title' );
// Add categories below the title.
function add_categories_below_title() {
echo get_the_category_list();
}
add_action( 'generate_after_entry_title', 'add_categories_below_title' );
// Custom "Read More" button.
function my_read_more() {
$read_more_button = '<div class="read-more-button-wrapper"><a class="button" href=' . esc_url( get_permalink( get_the_ID() ) ) . '>Read More</a></div>';
return $read_more_button;
}
add_filter( 'generate_excerpt_more_output', 'my_read_more');
// Move the custom "Read More" button below the excerpt.
function add_read_more_after_excerpt() {
echo generate_excerpt_more('Read More');
}
add_action( 'generate_after_content', 'add_read_more_after_excerpt' );
/*
Theme Name: GeneratePress Child
Theme URI: https://generatepress.com
Description: Default GeneratePress child theme
Author: Tom Usborne
Author URI: https://tomusborne.com
Template: generatepress
Version: 0.1
*/
/*
* Use an UL to list the categories, but make
* the UL behave like an inline with no delimiters.
*/
.post-categories {
list-style-type: none;
margin-top: 2%;
margin-left: 0 !important;
}
.post-categories a {
border: 1.5px solid black;
border-radius: 5px;
padding: .75%;
}
.post-categories > li {
display: initial;
}
/* Remove default date, author, categories,
and comments meta. */
.entry-meta {
display: none;
}
/* Date Styling */
.date-wrapper {
margin-bottom: 2%;
}
/* Read More Button Styling */
.read-more-button-wrapper {
margin-top: 2%;
}
@marklchaves
Copy link
Author

marklchaves commented Mar 29, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment