• Skip to main content
  • Skip to primary sidebar

WordPress, Genesis Framework and Storefront customization tutorials

  • Archive
    • Free
    • Premium
  • Blog
  • About
  • Contact
  • Newsletter
  • Login
Home » Free » Page 16

Free

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;
}
?>

Filed Under: Free Tagged With: CPT

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(); ?>

Filed Under: Free Tagged With: CPT

How to get post title slug


<?php 
    global $post;
    $post_slug=$post->post_name;
?>

Filed Under: Free Tagged With: PHP

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" );
});

Filed Under: Free Tagged With: jQuery

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' );

Filed Under: Free Tagged With: Bootstrap

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' );

Filed Under: Free Tagged With: Genesis

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;
}

Filed Under: Free Tagged With: CSS

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 );

Filed Under: Free Tagged With: WooCommerce

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 );

Filed Under: Free Tagged With: WooCommerce

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);

Filed Under: Free Tagged With: WooCommerce

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' );

Filed Under: Free Tagged With: PHP

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' );


Filed Under: Free Tagged With: PHP

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' );

Filed Under: Free Tagged With: PHP

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;}

}

Filed Under: Free Tagged With: Genesis

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;
    });

});

Filed Under: Free Tagged With: WooCommerce

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();

Filed Under: Free Tagged With: Genesis

WPML if statement

Method 1

Method 2

Filed Under: Free Tagged With: WPML

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;
}

Filed Under: Free Tagged With: PHP

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; ?>

Filed Under: Free Tagged With: ACF

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');

?>

Filed Under: Free Tagged With: Bootstrap

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 14
  • Page 15
  • Page 16
  • Page 17
  • Page 18
  • Page 19
  • Go to Next Page »

Primary Sidebar

Gabor Flamich

Hi! I'm Gabor.
I write tutorials on WordPress and WooCommerce.

MacBook

12 Essential Snippets for Genesis Developers

Subscribe to my Newsletter to view my basic collection of Genesis snippets that I use for my projects!

Sign Up for Free
  • Facebook
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube
UpdraftPlus Premium

Tags

ACF Ajax Analytics API Bootstrap Breadcrumb category CPT CSS fetch FSE Genesis Google Maps Gutenberg HTML Isotope JavaScript jQuery loop Map Menu Parallax PHP Rest API SASS SEO SQL Storefront SVG tab tag manager tags Taxonomy Tool upsell Webpack Wholesale WooCommerce WordPress WPML

Disclosure: Some of the links in this site are affiliate links. I will be paid a commission if you use this link to make a purchase.

  • Privacy Policy / Terms of Service
© 2025 WP Flames - All Right Reserved