/* * * Let's us add options for customizing our theme * from the build in WordPress Customize screen. * Gives access to four methods we can use with * the hook. * */ function my_theme_customizations( $wp_customize ) { /* * The $wp_customize object we pass as a parameter * gives us access to the following methods: * * - add_setting() * - add_section() * - add_control() * - get_setting() * */ } add_action( 'customize_register', 'my_theme_customizations' );
Example of the admin_head() action hook
/* * Let's us display code inside of the <head> * tags in the WordPress admin area. * We will use this to custom CSS for our plugin * with the WordPress admin area * */ function my_plugin_back_end_css() { wp_enqueue_style( 'my_plugin_back_end_css', plugins_url('css/back-end.css', __FILE__) ); } add_action( 'admin_head', 'my_plugin_back_end_css' );
Add Full Width Wrap to Genesis Site-Inner
.entry { background-color:transparent; } .site-inner { max-width: none; } @media only screen and (max-width: 1139px) { .site-inner{max-width: none;} }
How to fix WooCommerce Terms and Conditions link on Checkout Page
jQuery(function($){ $( "a.woocommerce-terms-and-conditions-link" ).unbind( "click" ); $( "body" ).on('click', 'a.woocommerce-terms-and-conditions-link', function( event ) { $(this).attr("target", "_blank"); window.open( $(this).attr("href")); return false; }); });
Genesis page template
<?php /** * Template name: Sales */ //Sales cover add_action('genesis_after_header', 'add_sales_cover'); function add_sales_cover(){ include('inc/sales-cover.php'); } genesis();
WPML if statement
Method 1
Method 2
Enqueue Google Font
If You want to use Google Font on your WordPress site, You will need to enqueue it in the functions.php
Now just add the following CSS
* { font-family: 'Poppins', sans-serif; }
Loop Zillow CPT
<?php $the_query = new WP_Query( $args ); ?> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <div class="review-content"> <?php include('stars-main.php'); ?> <label class="highly"> <?php if( get_field('main_review') == '5') : ?> Highly likely to recommend <?php endif; ?> <?php if( get_field('main_review') == '4') : ?> Likely to recommend <?php endif; ?> <?php if( get_field('main_review') == '3') : ?> Might recommend <?php endif; ?> </label> <br> <ul class="review-metadata"> <li><?php the_title(); ?></li> <li><?php the_field('short_description'); ?></li> <li> <?php if( get_field('primary_point_of_contact') ): ?> <li><?php the_field('primary_point_of_contact'); ?></li> <?php endif; ?> </li> </ul> <div class="reviews-sub-ratings"> <ul class="ratings"> <li><span class="ratings-col">Local knowledge:</span> <?php include('stars-local.php'); ?></li> <li><span class="ratings-col">Process expertise:</span> <?php include('stars-process.php'); ?></li> <li><span class="ratings-col">Responsiveness:</span> <?php include('stars-respo.php'); ?></li> <li><span class="ratings-col">Negotiation skills:</span> <?php include('stars-nego.php'); ?></li> </ul> </div> <div class="review-body"> <?php the_field('review'); ?> </div> </div> <?php endwhile; else: echo 'No reviews yet.'; endif; ?> <?php wp_reset_postdata(); ?>
ACF hide if empty custom field
<!--ACF HIDE IF EPMTY CUSTOM FIELD --> <?php if( get_field('mobil') ): ?> <li><?php the_field('mobil'); ?></li> <?php endif; ?>
<!--IF ELSE HIDE - SHOW DIV IF THE_FILED IS EMPTY!!!!!!!--> <?php if( get_field('hogyan_keszult_link') ){ ?> <style type="text/css">.hogy-keszul-cta{ display:block; }</style> <?php }?>
//CUSTOM FIELDS SELECET OPTIONS <?php if( get_field('color') == 'red' ): ?> <p>Selected the Red choice!</p> <?php endif; ?>
Testimonial Carousel – Custom Post Type Loop
<?php //TESTIMONIAL function post_carousel_loop() { ?> <div class="container"> <div id="myCarousel" class="carousel slide" data-ride="carousel"> <div class="carousel-inner" role="listbox"> <!--LOOP ACTIVE ITEMS--> <?php wp_reset_postdata(); $the_query = new WP_Query(array( 'post_type' => 'testimonial', 'posts_per_page' => 1 )); while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <div class="carousel-item active"> <div class="row"> <div class="col-md-12"> <h2 class="carousel-title">Our Patients Say</h2> <?php the_excerpt(); ?> <h4 class="author"> <?php the_title(); ?> </h4> </div> </div><!--row--> </div><!--item-active--> <?php endwhile; wp_reset_postdata(); ?> <!--LOOP ITEMS--> <?php $the_query = new WP_Query(array( 'post_type' => 'testimonial', 'posts_per_page' => 3, 'offset' => 1 )); while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <div class="carousel-item"> <div class="row"> <div class="col-md-12"> <h2 class="carousel-title">Our Patients Say</h2> <?php the_excerpt(); ?> <h4 class="author"> <?php the_title(); ?> </h4> </div> </div><!--row--> </div><!--item-active--> <?php endwhile; wp_reset_postdata(); ?> </div> <div class="carousel-control-wrapper"> <a class="carousel-control-prev" data-target="#myCarousel" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" data-target="#myCarousel" role="button" data-slide="next"> <i class="fas fa-chevron-right"></i> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </div> </div> <?php } add_shortcode('testimonial-carousel', 'post_carousel_loop'); ?>
Loop team members
<?php wp_reset_postdata(); $args = array( 'post_type' => 'team', 'posts_per_page' => 100 ); $the_query = new WP_Query( $args ); ?> <div class="container"> <div class="row"> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <div class="col-md-4"> <div class="card member"> <a href="<?php the_permalink(); ?>"> <img class="card-img-top" src="<?php the_field('image'); ?>" alt=""> </a> <div class="card-body"> <h3 class="card-title"><?php the_title(); ?></h3> <p class="card-text hidden"><?php the_field('description'); ?></p> <a class="hidden" href="<?php the_permalink(); ?>" class="btn btn-primary">Read more</a> </div> </div> </div> <?php endwhile; endif; ?> </div><!--row--> </div><!--container--> <?php wp_reset_postdata(); ?>
Add Product to WooCommerce Cart Automatically
add_action( 'template_redirect', 'snippet_add_product_to_cart' ); function snippet_add_product_to_cart() { // select ID $product_id = 21874; //check if product already in cart if ( WC()->cart->get_cart_contents_count() == 0 ) { // if no products in cart, add it WC()->cart->add_to_cart( $product_id ); } }
Add Product to Cart When Visiting a Specific Page ID
add_action( 'wp', 'add_product_to_cart_on_page_id_load' ); function add_product_to_cart_on_page_id_load() { // product ID to add to cart $product_id = 21874; // page ID to target if ( is_page( 19473 ) ) { WC()->cart->empty_cart(); WC()->cart->add_to_cart( $product_id ); } }
Genesis Custom Footer
Simple shortcode function
If the shortcode produces a lot of HTML then ob_start can be used to capture output and convert it to a string as follows:
Add custom field to single product page
//ADD CUSTOM FIELD TO SINGLE PRODUCT BEFORE ADD TO CART BUTTON add_action( 'woocommerce_single_variation', 'add_custom_field_before_addtocart', 5 ); function add_custom_field_before_addtocart() { include('woo/custom-field.php'); }
<?php the_field('custom'); ?>
Add custom widget to anywhere you want
Register widget in functions.php
// ========================================================================= // REGISTER NEW WIDGET // ========================================================================= function custom_widgets_init() { register_sidebar( array( 'name' => 'Custom Widget', 'id' => 'custom-widget-id', 'before_widget' => '<div class="custom-widget">', 'after_widget' => '</div>', 'before_title' => '<h4 class="custom-title">', 'after_title' => '</h4>', ) ); } add_action( 'widgets_init', 'custom_widgets_init' );
Place this code where you want to appear the widget
<?php dynamic_sidebar('Custom Widget'); ?>
Facebook Likebox to Genesis
Genesis cover
If You want to create a GSAP Animation for the cover build up with HTML, CSS and JavaScript and hook in to the frontpage’s before content:
Translate without PO Edit
<?php function wpf_filter_gettext( $translated, $original, $domain ) { if ( $translated == "OLD_TEXT" ) { $translated = "NEW_TEXT"; } return $translated; } add_filter( 'gettext', 'wpf_filter_gettext', 10, 3 );
Remove translation
function remove_translation( $translated_text, $untranslated_text, $domain ) { $removable_text = 'Ide kerül az eltávolítani kívánt kifejezés.'; if ($untranslated_text === $removable_text ) { return ''; } return $translated_text; }