Skip to content

Instantly share code, notes, and snippets.

View dancywritter's full-sized avatar
🏠
Working from home

Haroon Rasheed dancywritter

🏠
Working from home
View GitHub Profile
@dancywritter
dancywritter / QRLogo.php
Created December 6, 2021 12:27 — forked from NTICompass/QRLogo.php
QR Code + Logo Generator
<?php
/**
* QR Code + Logo Generator
*
* http://labs.nticompassinc.com
*/
$data = isset($_GET['data']) ? $_GET['data'] : 'http://labs.nticompassinc.com';
$size = isset($_GET['size']) ? $_GET['size'] : '200x200';
$logo = isset($_GET['logo']) ? $_GET['logo'] : FALSE;
@dancywritter
dancywritter / lenura_empty_cart_before_add.php
Created September 23, 2021 23:31 — forked from viniciusrtf/lenura_empty_cart_before_add.php
WooCommerce Hook: Empty cart before adding a new product to cart WITHOUT throwing woocommerce_cart_is_empty
<?php
/**
* Hook: Empty cart before adding a new product to cart WITHOUT throwing woocommerce_cart_is_empty
*/
add_action ('woocommerce_add_to_cart', 'lenura_empty_cart_before_add', 0);
function lenura_empty_cart_before_add() {
global $woocommerce;
// Get 'product_id' and 'quantity' for the current woocommerce_add_to_cart operation
@dancywritter
dancywritter / functions.pnp
Created August 8, 2021 08:31 — forked from gmmedia/functions.php
Add featured image column to WP admin panel - posts AND pages
/**
* Add featured image column to WP admin panel - posts AND pages
* See: https://j0e.org/featured-image-admin/
*/
// Set thumbnail size
add_image_size( 'j0e_admin-featured-image', 60, 60, false );
// Add the posts and pages columns filter. Same function for both.
add_filter('manage_posts_columns', 'j0e_add_thumbnail_column', 2);
@dancywritter
dancywritter / gist:b156c6a1fbf44ed7cd9ffc12a8376fa7
Created March 11, 2021 18:42 — forked from wpmark/gist:9d5d2395cb01a2de0179
Check If WordPress Post is Older than X Days
<?php
/*******************************
* this will work in the loop
*******************************/
/* check if the posts publish date is older than 60 days */
if( strtotime( $post->post_date ) < strtotime('-60 days') ) {
/* post is older than 60 days - do something with it!! */
@dancywritter
dancywritter / countries
Created February 22, 2021 07:45 — forked from kalinchernev/countries
Plain text list of countries
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua & Deps
Argentina
Armenia
Australia
Austria
@dancywritter
dancywritter / repeater_array.php
Created November 6, 2020 17:42 — forked from luclemo/repeater_array.php
Creating objects using ACF repeater fields #wordpress #acf
<?php
// check if the repeater field has rows of data
if( have_rows('drop-down_menus') ) :
$array = array(); // empty array, must be declared outside of while loop
$i = 0; // incrementer
// loop through the rows of data and add to our array
while ( have_rows('drop-down_menus') ) : the_row();
@dancywritter
dancywritter / Sitemap.xml
Created October 20, 2020 10:31 — forked from misterebs/Sitemap.xml
Create sitemap.xml for wordpress site without plugins
Copy this code to function.php
//Sitemap XML
/*
function to create sitemap.xml file in root directory of site
*/
@dancywritter
dancywritter / functions.php
Created October 14, 2020 19:56 — forked from mustardBees/functions.php
Filter a few parameters into WordPress YouTube oEmbed requests. Enable modest branding which hides the YouTube logo. Remove the video title and uploader information. Prevent related videos from being shown once the video has played.
<?php
/**
* Filter a few parameters into YouTube oEmbed requests
*
* @link http://goo.gl/yl5D3
*/
function iweb_modest_youtube_player( $html, $url, $args ) {
return str_replace( '?feature=oembed', '?feature=oembed&modestbranding=1&showinfo=0&rel=0', $html );
}
add_filter( 'oembed_result', 'iweb_modest_youtube_player', 10, 3 );
@dancywritter
dancywritter / add-nav-parent-count.php
Created August 25, 2020 16:36 — forked from jessepearson/add-nav-parent-count.php
Functions to add a parent count to WordPress nav menus. This is useful if you need to change nav element size based on the number of parent/top level elements.
<?php
/**
* Gets the count of the parent items in a nav menu based upon the id specified.
*
* @param string $nav_id The id of the nav item to get the parent count for.
* @return bool|int False on fail, or the count of how many parent items there are.
* @uses wp_get_nav_menu_items
*/
function count_nav_parent_items( $nav_id = null ) {
@dancywritter
dancywritter / youtube_id_regex.php
Created August 8, 2020 11:18 — forked from ghalusa/youtube_id_regex.php
Extract the YouTube Video ID from a URL in PHP
<?php
// Here is a sample of the URLs this regex matches: (there can be more content after the given URL that will be ignored)
// http://youtu.be/dQw4w9WgXcQ
// http://www.youtube.com/embed/dQw4w9WgXcQ
// http://www.youtube.com/watch?v=dQw4w9WgXcQ
// http://www.youtube.com/?v=dQw4w9WgXcQ
// http://www.youtube.com/v/dQw4w9WgXcQ
// http://www.youtube.com/e/dQw4w9WgXcQ
// http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ