Skip to content

Instantly share code, notes, and snippets.

@wpflames
wpflames / composer.json
Created February 3, 2022 19:15
Install WordPress Plugins with Composer from Command Line
{
"name": "acme/brilliant-wordpress-site",
"description": "My brilliant WordPress site",
"repositories":[
{
"type":"composer",
"url":"https://wpackagist.org",
"only": [
"wpackagist-plugin/*",
"wpackagist-theme/*"
@wpflames
wpflames / functions.php
Last active February 2, 2022 13:59
Remove junk from WordPress head
// =============================================================
// REMOVE JUNK FROM WORDPRESS HEAD SECTION
// =============================================================
// Remove wordpress version
remove_action('wp_head', 'wp_generator');
// Remove emoji support
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
@wpflames
wpflames / functions.php
Created February 2, 2022 09:44
Enqueue Google Font in WordPress
// =============================================================
// ENQUEUE GOOGLE FONT
// =============================================================
function genesis_load_google_fonts() {
wp_enqueue_style( 'google-font-poppins', '//fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap', array(), 1.0);
}
add_action( 'wp_enqueue_scripts', 'genesis_load_google_fonts' );
@wpflames
wpflames / functions.php
Created January 31, 2022 21:15
Remove product content based on category
// =========================================================================
// REMOVE PRODUCT CONTENT BASED ON CATEGORY
// =========================================================================
function remove_product_content() {
if ( is_product() && has_term( 'Flowers', 'product_cat' ) ) {
// Remove the images
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
// For a full list of what can be removed please see woocommerce-hooks.php
}
}
@wpflames
wpflames / functions.php
Created January 31, 2022 16:38
Get Current Shipping Method WooCommerce
// =========================================================================
// Get Current Shipping Method WooCommerce
// =========================================================================
function get_current_shipping_method(){
$shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
foreach ( $shipping_methods as $shipping_method){
echo '<div id="output" class="chosen-shipping">';
if($shipping_method === 'flat_rate:1'){
echo 'Flower sending ';
}
@wpflames
wpflames / post-types.php
Created January 30, 2022 10:14
Custom Post Type with variables
<?php
// Events
function custom_post_type_event() {
$post_type_slug = 'event';
$post_type_name = ucfirst($post_type_slug);
register_post_type($post_type_slug, array(
'public' => true,
'show_in_rest' => true,
'has_archive' => true,
@wpflames
wpflames / wp-query.php
Created January 29, 2022 16:30
Order upcoming events by ACF datepicker
<?php
// Order by ACF datepicker
$args = new WP_Query(array(
'post_type' => 'event',
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
@wpflames
wpflames / post-types.php
Last active December 21, 2023 18:21
Create a Custom Post Type in WordPress
<?php
function custom_post_types() {
// Events
register_post_type('event', array(
'public' => true,
'capability_type' => 'event',
'map_meta_cap' => true,
'show_in_rest' => true,
'has_archive' => true,
@wpflames
wpflames / functions.php
Created January 28, 2022 14:13
Minimum cart amount for specific category in WooCommerce
<?php
// =========================================================================
// MINIMUM CART AMOUNT FOR SPECIFIC CATEGORY IN WOOCOMMERCE
// =========================================================================
function minimum_order_amount_for_subcategories() {
$term_slug = 'kiegeszitok'; // <== Define the targeted main product category slug
$term_name = 'Kiegészítők'; // <== Define the targeted main product category slug
$threshold_huf = 5000; // <== Define the minimum amount in HUF
$threshold_eur = 14; // <== Define the minimum amount in EUR
@wpflames
wpflames / breadcrumbs.php
Created January 28, 2022 09:49
How to create custom breadcrumbs in WordPress
<?php
$parent_id = wp_get_post_parent_id(get_the_ID());
$parent_url = get_the_permalink($parent_id);
$parent_title = get_the_title($parent_id);
// If ID > 0
if($parent_id){ ?>
<ul class="breadcrumbs">
<li><a href="<?php echo $parent_url; ?>"><?php echo $parent_title; ?></a></li>
<li><span><?php the_title(); ?></span></li>