Free
How to add True / False checkbox with ACF
<?php if( get_field('field') ){
echo '';
}
else{
echo '';
}
?>
How to echo CPT taxonomy name and slug
Echo taxonomy slug
<?php foreach (get_the_terms(get_the_ID(), 'your_taxonomy') as $cat) {
echo $cat->slug;
}
?>
Echo taxonomy name
<?php foreach (get_the_terms(get_the_ID(), 'your_taxonomy') as $cat_name) {
echo $cat_name->name;
}
?>
Loop Custom Post Type Sub Category
<?php
wp_reset_postdata();
$args = array(
'post_type' => 'posttype',
'posts_per_page' => 20,
'tax_query' => array(
array(
'taxonomy' => 'taxonomy',
'field' => 'slug',
'terms' => 'subcategory',
),
),
);
$query = new WP_Query( $args ); ?>
<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>
How to get post title slug
<?php
global $post;
$post_slug=$post->post_name;
?>
jQuery Custom Events – click event- add / remove classes
Example
<div class="room" id="kitchen">
<div class="lightbulb on"></div>
<div class="switch"></div>
<div class="switch"></div>
<div class="clapper"></div>
</div>
$( ".switch, .clapper" ).click(function() {
var light = $( this ).closest( ".room" ).find( ".lightbulb" );
if ( light.is( ".on" ) ) {
light.removeClass( "on" ).addClass( "off" );
} else {
light.removeClass( "off" ).addClass( "on" );
}
});
$( ".lightbulb" ).on( "light:toggle", function( event ) {
var light = $( this );
if ( light.is( ".on" ) ) {
light.removeClass( "on" ).addClass( "off" );
} else {
light.removeClass( "off" ).addClass( "on" );
}
});
$( ".switch, .clapper" ).click(function() {
var room = $( this ).closest( ".room" );
room.find( ".lightbulb" ).trigger( "light:toggle" );
});
Enqueue Bootstrap CDN in WordPress
// =========================================================================
// BOOTSTRAP CSS
// =========================================================================
function enqueue_bootstrap_styles(){
wp_enqueue_style('bootstrap_css', '//stackpath.bootstrapcdn.com/bootstrap/4.4.0/css/bootstrap.min.css');
}
add_action( 'wp_enqueue_scripts', 'enqueue_bootstrap_styles' );
// =========================================================================
// BOOTSTRAP JAVASCRIPT
// =========================================================================
function enqueue_bootstrap_scripts() {
wp_enqueue_script( 'bootstrap_jquery', '//code.jquery.com/jquery-3.4.1.slim.min.js', array(), '3.3.1', true );
wp_enqueue_script( 'bootstrap_popper', '//cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js', array(), '1.14.7', true );
wp_enqueue_script( 'bootstrap_javascript', '//stackpath.bootstrapcdn.com/bootstrap/4.4.0/js/bootstrap.min.js', array(), '4.3.1', true );
}
add_action( 'wp_enqueue_scripts', 'enqueue_bootstrap_scripts' );
How to Move Genesis Nav Above the Header
//How to Move Genesis Nav Above the Header remove_action( 'genesis_after_header', 'genesis_do_nav' ); add_action( 'genesis_before_header', 'genesis_do_nav' );
Contact Form 7 Placeholder Hide on Focus
jQuery(document).ready(function(){
jQuery('input,textarea').focus(function(){
jQuery(this).data('placeholder',jQuery(this).attr('placeholder'))
.attr('placeholder','');
}).blur(function(){
jQuery(this).attr('placeholder',jQuery(this).data('placeholder'));
});
});
Syntax of CF7 placeholder
[text* your-name placeholder "NAME"]
CSS for placeholder
::-webkit-input-placeholder { /* WebKit browsers */
color: #fff !important;
opacity: 1;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #fff !important;
opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #fff !important;
opacity: 1;
}
:-ms-input-placeholder { /* Internet Explorer 10+ */
color: #fff !important;
opacity: 1;
}
Search by product SKU
/**
* Search by product SKU
*/
function wpninja_product_search_sku( $join, $query ) {
if ( ! $query->is_main_query() || is_admin() || ! is_search() || ! is_woocommerce() ) {
return $join;
}
global $wpdb;
$join .= " LEFT JOIN {$wpdb->postmeta} wpninja_post_meta ON {$wpdb->posts}.ID = wpninja_post_meta.post_id ";
return $join;
}
add_filter( 'posts_join', 'wpninja_product_search_sku', 10, 2 );
/**
* Modify the search query with posts_where.
*/
function wpninja_product_search_where( $where, $query ) {
if ( ! $query->is_main_query() || is_admin() || ! is_search() || ! is_woocommerce() ) {
return $where;
}
global $wpdb;
$where = preg_replace(
"/\(\s*{$wpdb->posts}.post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"({$wpdb->posts}.post_title LIKE $1) OR (wpninja_post_meta.meta_key = '_sku' AND wpninja_post_meta.meta_value LIKE $1)", $where );
return $where;
}
add_filter( 'posts_where', 'wpninja_product_search_where', 10, 2 );
Show SKU above the product title
//Show SKU above the product title
function fdesign_show_sku(){
global $product;
echo '<small>Cikkszám:</small> <small>' . $product->get_sku() .'</small>';
}
add_action( 'woocommerce_before_single_product_summary', 'fdesign_show_sku', 5 );
Show Product Search in Header
//Show Product Search in Header
function new_nav_menu_items($items, $args) {
$my_product_search = get_product_search_form( $echo );
if($args->theme_location == 'main_navigation'){
$items = $items . $my_product_search;
}
return $items;
}
add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);
Example of the comments_template() filter
/*
*
* Let's us override the default comment template
* located at wp-includes/comment-template.php and
* use our own comment file instead.
*
*/
function custom_comment_template( $comment_template ) {
return dirname(__FILE__) . '/inc/custom-comment-template.php';
}
add_filter( 'comments_template', 'custom_comment_template' );
Example of the customize_register() action hook
/*
*
* 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;
}