Free
How to hide WordPress Update notification on admin panel?
add_action('admin_menu','hide_wordpress_update_nag');
function hide_wordpress_update_nag() {
if (is_admin()) {
remove_action('admin_notices', 'update_nag', 3);
}
}
If product is out of stock echo something – WooCommerce product single
//Echo something if product is out of stock
add_action( 'woocommerce_share', 'add_out_of_stock_custom_message', 5 );
function add_out_of_stock_custom_message() {
global $product;
if ( ! $product->is_in_stock() ) {
echo '';
}
}
Disable Barion if shipping method is free shipping
//Disable Payment Gateway For Specific Shipping Method
add_filter( 'woocommerce_available_payment_gateways', 'wpninja_gateway_disable_shipping_326' );
function wpninja_gateway_disable_shipping_326( $available_gateways ) {
global $woocommerce;
if ( !is_admin() ) {
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'free_shipping' ) ) {
unset( $available_gateways['barion'] );
}
}
return $available_gateways;
}
How to loop related posts by tags
<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo '<h3>Kapcsolódó bejegyzések</h3>';
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'posts_per_page'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args); ?>
<div class="row">
<?php if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="col-md-4">
<div class="card">
<div class="item-hover circle effect13 top_to_bottom">
<a href="<?php the_permalink(); ?>">
<div class="card-body">
<h3 class="card-title"><?php the_title(); ?></h3>
<p class="readmore"><i class="fas fa-angle-right"></i> <?php include('translate/tovabb.php'); ?></p>
</div>
<div class="info">
<div class="info-back home-posts">
<h3 class="label"><?php the_title(); ?></h3>
<p class="readmore-postsback"><i class="fas fa-angle-right"></i><?php include('translate/tovabb.php'); ?></p>
</div>
</div>
</a>
</div>
</div>
</div>
<?php
endwhile;
}
?>
</div>
<?php
wp_reset_query();
}
?>
WordPress Debug Mode
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );
Bootstrap Carousel Slider as Background Image – Cover
<div id="slider-wrapper" class="container-fluid">
<div id="mySlider" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#mySlider" data-slide-to="0" class="active"></li>
<li data-target="#mySlider" data-slide-to="1"></li>
<li data-target="#mySlider" data-slide-to="2"></li>
<li data-target="#mySlider" data-slide-to="3"></li>
</ol>
<div class="carousel-inner" role="listbox">
<!--LOOP ACTIVE ITEMS-->
<?php wp_reset_postdata();
$the_query = new WP_Query(array(
'post_type' => 'slider',
'posts_per_page' => 1
));
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="carousel-item active" style="background-image: url('<?php the_field('slide'); ?>');">
<div class="carousel-caption">
<div class="carousel-head">
<h2><?php the_title(); ?></h2>
</div>
<p><?php the_field('caption_text'); ?></p>
<?php echo do_shortcode('[cta]'); ?>
</div>
</div><!--item-active-->
<?php endwhile; wp_reset_postdata(); ?>
<!--LOOP ITEMS-->
<?php
$the_query = new WP_Query(array(
'post_type' => 'slider',
'posts_per_page' => 2,
'offset' => 1
));
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="carousel-item" style="background-image: url('<?php the_field('slide'); ?>');">
<div class="carousel-caption">
<div class="carousel-head">
<h2><?php the_title(); ?></h2>
</div>
<p><?php the_field('caption_text'); ?></p>
<?php echo do_shortcode('[cta]'); ?>
</div>
</div><!--item-active-->
<?php endwhile; wp_reset_postdata(); ?>
</div>
<div class="carousel-control-wrapper hidden">
<a class="carousel-control-prev" data-target="#mySlider" 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="#mySlider" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
Search only in specific Custom Post Types
//Search only in specific Custom Post Types
function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('post','page'));
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
How to create 4 col Bootstrap Carousel from Custom Post Type in Genesis
<!-- Carousel -->
<div id="promo-carousel" class="carousel job-carousel-wrapper slide" data-ride="carousel" data-interval="3000">
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php
// Item size (set here the number of posts for each group)
$i = 4;
// Set the arguments for the query
global $post;
$args = array(
'numberposts' => 16, // -1 is for all
'post_type' => 'munkak', // or 'post', 'page'
'orderby' => 'title', // or 'date', 'rand'
'order' => 'ASC', // or 'DESC'
);
// Get the posts
$myposts = get_posts($args);
// If there are posts
if($myposts):
// Groups the posts in groups of $i
$chunks = array_chunk($myposts, $i);
$html = "";
/*
* Item
* For each group (chunk) it generates an item
*/
foreach($chunks as $chunk):
// Sets as 'active' the first item
($chunk === reset($chunks)) ? $active = "active" : $active = "";
$html .= '<div class="carousel-item '.$active.'"><div class="container"><div class="row">';
/*
* Posts inside the current Item
* For each item it generates the posts HTML
*/
foreach($chunk as $post):
include('variables.php');
$html .= '<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">';
$html .= '<a class="cat-link" href="'.get_the_permalink().'">';
$html .= get_the_post_thumbnail();
$html .= '<h4>'.get_the_title($post->ID).'</h4>';
$html .= '<ul>';
$html .= '<li>'.$orszag.'</li>';
$html .= '<li>'.get_field("munkaber").'</li>';
$html .= '</ul>';
$html .= '</a>';
$html .= '</div>';
endforeach;
$html .= '</div></div></div>';
endforeach;
// Prints the HTML
echo $html;
endif;
?>
</div> <!-- carousel inner -->
<!-- Controls -->
<div class="job-carousel carousel-control-wrapper">
<a class="carousel-control-prev" data-target="#promo-carousel" role="button" data-slide="prev">
<i class="fas fa-chevron-left"></i>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" data-target="#promo-carousel" role="button" data-slide="next">
<i class="fas fa-chevron-right"></i>
<span class="sr-only">Next</span>
</a>
</div>
</div> <!-- /carousel -->
Add Images to CPT Taxonomy
I use for add images to categories this plugin: Categories Images
<div class="grid row kategoria">
<?php foreach (get_terms('kategoria') as $cat) : ?>
<div class="col-xs-12 col-sm-6 col-md-3">
<a class="cat-link" href="<?php echo get_term_link($cat->slug, 'kategoria'); ?>">
<figure class="effect-ming">
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
<figcaption>
<h2 class="kategoria"><?php echo $cat->name; ?></h2>
<p class="hover hide"><?php echo $cat->name; ?></p>
</figcaption>
</figure>
</a>
</div>
<?php endforeach; ?>
</div>
Custom Post Type Taxonomy Archive Page in Genesis
Create a file with name taxonomy-yourtaxonomy.php
<?php
//Include taxonomy template file
add_action('genesis_entry_header', 'add_custom_category');
function add_custom_category(){
include('loop/taxonomy-archive.php');
}
//Add wrapper open
add_action('genesis_before_while', 'add_grid_wrapper_open');
function add_grid_wrapper_open(){
echo '<div class="grid row">
';
}
//Add wrapper close
add_action('genesis_after_endwhile', 'add_grid_wrapper_close');
function add_grid_wrapper_close(){
echo '
</div>';
}
genesis();
Create another file in loop folder with name taxonomy-archive.php
<div class="card melo">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'full', array('class' => 'card-img-top') ); ?>
</a>
<div class="card-body">
<h4 class="card-title"><?php the_title(); ?></h4>
<div class="card-text">
</div>
</div>
</div>
How to add Featured Image to Custom Post Type Sidebar in Genesis
//ADD FEATURED IMAGE TO CUSTOM POST TYPE SIDEBAR IN GENESIS
function your_custom_function(){
if (is_singular( 'your_cpt' )) {
the_post_thumbnail( 'medium', array('class' => '') );
}
}
add_action('genesis_before_sidebar_widget_area', 'your_custom_function');
ACF – Echo something when the field is empty
<?php function cover_subtitle() {
if( get_field('slug') ){ the_field('slug'); }
else{ echo 'Hello!'; }
}
?>
Hide something if user logged out / Show only for logged in users
Put these snippet in functions.php
//HIDE IF LOGGED OUT
function hide_if_logged_out(){
if ( is_user_logged_in() ) {
echo '';
} else {
echo 'hidden';
}
}
Call the function as class
<div class="container <?php echo hide_if_logged_out(); ?>">
How to get post title slug
<?php
global $post;
$post_slug=$post->post_name;
?>
How to add Social Icons to Genesis Menu
//ADD SOCIAL ICON TO GENESIS MENU
function wdm_add_menu_items( $menu, $args ) {
// check if it is the 'primary' navigation menu
if ( 'primary' === $args->theme_location )
{
// add the search form
ob_start();
get_search_form();
$search = ob_get_clean();
$menu .= '<li id="menu-item-125" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-125">
<a href="#" target="_blank">
<i class="fb-icon fab fa-facebook-f"></i>
</a>
</li>';
}
return $menu;
}
add_filter( 'wp_nav_menu_items', 'wdm_add_menu_items', 10, 2 );
How to set Excerpt Length
Add this snippet to functions.php
How to force full width content in Genesis Custom Post Type Single Page
// Add support for Genesis layouts to listings post type
add_post_type_support( 'your_post_type', 'genesis-layouts' );
// Force layout on custom post type
add_filter('genesis_site_layout', 'your_post_type_layout');
function your_post_type_layout($opt) {
if ( 'your_post_type' == get_post_type() )
$opt = 'full-width-content';
return $opt;
}
Add support for Genesis Layouts to Custom Post Type
// Add support for Genesis layouts to custom post type add_post_type_support( 'munkak', 'genesis-layouts' );
How to add row after every 4 col in WordPress loop
<?php
$args = array(
'post_type' => 'posttype',
'posts_per_page' => 20,
'tax_query' => array(
array(
'taxonomy' => 'taxonomy',
'field' => 'slug',
'terms' => 'terms',
),
),
);
$query = new WP_Query( $args );
$counter = 0;
$post_count = $the_query->post_count;
?>
<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<?php
if ($counter == 0) {
echo '<div class="row">';
}
?>
<!------------------------------------->
<?php
$counter++;
if ( $counter % 4 == 0 || $post_count == $counter ) {
echo '</div> <div class="row">';
}
?>
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>