Skip to content

Instantly share code, notes, and snippets.

Avatar

Brad Dalton braddalton

View GitHub Profile
View functions.php
function default_category_featured_image() {
global $post;
$featured_image_exists = has_post_thumbnail($post->ID);
if (!$featured_image_exists) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
View functions.php
add_filter('the_category_list', 'only_show_first_category');
function only_show_first_category( $cats ) {
return [$cats[0]];
}
View functions.php
add_action( 'wp_enqueue_scripts', 'genesis_enqueue_lightbox_script_styles' );
function genesis_enqueue_lightbox_script_styles() {
wp_enqueue_script( 'lightbox-js', get_stylesheet_directory_uri() . '/lightbox.js', [ 'jquery' ], genesis_get_theme_version(), true );
wp_enqueue_style( 'lightbox-styles', get_stylesheet_directory_uri() . '/lightbox.css', [], genesis_get_theme_version() );
}
View functions.php
add_action ( 'genesis_entry_footer', 'wpsites_attachment_image_navigation' );
function wpsites_attachment_image_navigation() {
if ( wp_attachment_is_image( $post_id ) ) {
echo'<div class="attachment-image-navigation">';
previous_image_link( false, '<div class="previous-image alignleft">' . __( 'View Previous Image', '$text_domain' ) . '</div>' );
next_image_link( false, '<div class="next-image alignright">' . __( 'View Next Image', '$text_domain' ) . '</div>' );
echo'</div>';
}}
View functions.php
//* Save Custom Comment Form Field Meta Data
add_action( 'comment_post', 'save_custom_comment_field_data', 10, 1 );
function save_custom_comment_field_data( $comment_id ) {
if ( ( isset( $_POST['industry'] ) ) && ( $_POST['industry'] != '') )
$industry = wp_filter_nohtml_kses($_POST['industry']);
add_comment_meta( $comment_id, 'industry', $industry );
if ( ( isset( $_POST['title'] ) ) && ( $_POST['title'] != '') )
$title = wp_filter_nohtml_kses($_POST['title']);
add_comment_meta( $comment_id, 'title', $title );
@braddalton
braddalton / functions.php
Created Nov 18, 2020
1st Paginated Archive Page 1 post
View functions.php
add_action( 'pre_get_posts', 'posts_per_page_home' );
function posts_per_page_home($query) {
if ( $query->is_home() && $query->is_main_query() && get_query_var( 'paged' ) < 2 ) {
$query->set( 'posts_per_page', '1' );
}
}
@braddalton
braddalton / functions.php
Created Nov 18, 2020
Set Posts Per Page On Home Page
View functions.php
add_action( 'pre_get_posts', 'posts_per_page_home' );
function posts_per_page_home($query) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'posts_per_page', '1' );
}
}
View functions.php
add_filter( 'pre_get_posts', 'add_cpt_to_loop_and_feed' );
/**
* @author Brad Dalton
* @example http://wpsites.net/wordpress-tips/add-custom-post-type-to-rss-feed/
* @copyright 2014 WP Sites
*/
function add_cpt_to_loop_and_feed( $query ) {
if ( is_home() && $query->is_main_query() || is_feed() )
$query->set( 'post_type', array( 'post', 'your-cpt' ) );
@braddalton
braddalton / Remove Page Navigation Genesis
Last active Oct 14, 2020
Remove Pagination Genesis. This PHP code removes the page naviagtion from all archives Source http://wpsites.net/web-design/genesis-remove-page-navigation-pagination-from-any-archive-page/
View Remove Page Navigation Genesis
remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' );