Skip to content

Instantly share code, notes, and snippets.

View yratof's full-sized avatar
🍊
Eating an orange

Andrew yratof

🍊
Eating an orange
View GitHub Profile
@yratof
yratof / functions.php
Created June 2, 2015 12:35
Getting the Video ID from ACF OEmbed, then using that ID to call in videos without bloat
<?php
/* Parse the video uri/url to determine the video type/source and the video id */
function parse_video_uri( $url ) {
// Parse the url
$parse = parse_url( $url );
// Set blank variables
$video_type = '';
$video_id = '';
@yratof
yratof / functions.php
Created March 25, 2015 16:43
Advanced Custom Fields - Update Gallery with Gravity Forms
$gravity_form_id = 6; // gravity form id, or replace {$gravity_form_id} below with this number
add_filter("gform_after_submission_{$gravity_form_id}", 'jdn_set_post_acf_gallery_field', 10, 2);
function jdn_set_post_acf_gallery_field($entry, $form)
{
$gf_images_field_id = 42; // the upload field id
$acf_field_id = 'field_54804833b3067'; // the acf gallery field id
// get post
@yratof
yratof / functions.php
Created December 7, 2016 16:01
Woocommerce remove unused attributes on product variations
<?php
add_action( 'init', function() {
ini_set( 'memory_limit', '2048M' );
set_time_limit( 0 );
$posts = get_posts( [
'post_type' => 'product',
'posts_per_page' => -1
] );
$count = 0;
@yratof
yratof / functions.php
Created July 24, 2013 14:11
Wordpress WooCommerce 360 Images as the featured image
// This will make a new function called "get_the_slug()" which will get the page
// slug, for example, of the page is ...com/blog/news/story-name-here, then this
// will echo 'story-name-here'. I'm using this in WooCommerce for the product
// 360 images, because I need to rename each set of images so they become
// unique, I needed a way of getting separating them. The only drawback here, is
// that you need to know the slug before you make the images, AND if you rename
// that page, the images will break. SO. It's something that is experimental,
// but if monitored right, shouldn't be a problem! &
function get_the_slug( $id=null ){
<?php
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
@yratof
yratof / cpt.php
Last active August 12, 2023 18:02
Wordpress AJAX search through custom post type
<form role="search" method="post" class="search-form padding-4" action="<?php echo home_url( '/' ); ?>">
<label>
<span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ) ?></span>
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search...', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
<input class="post_type" type="hidden" name="post_type" value="frequent" />
</label>
<input type="submit" class="search-submit button brand" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>" />
</form>
<script type="text/javascript">
@yratof
yratof / functions.php
Created March 29, 2016 16:39
Flipping product images for Woocommerce
<?php
// Add the first gallery image to the item within the cateogry view.
// this hooks on to the content title before hook
function vakrerom_additional_image_on_category(){
global $product;
$attachment_ids = $product->get_gallery_attachment_ids();
if (!empty($attachment_ids)){
foreach( array_slice( $attachment_ids , 0, 1) as $attachment_id ) {
$image_link = wp_get_attachment_url( $attachment_id ); ?>
<span class="image--lookbook">
@yratof
yratof / remove-products.php
Created January 19, 2016 14:54
Remove products that are not needed. stupid products.
<?php
if ( 'supersecret' == @$_GET['supersecret']) {
add_action( 'wp_footer', function() {
$ids = [2487, 2488, 2489, 2490, 2491, 2492, 2493, 2494, 2495, 2496, 2497, 2498, 2499, 2500, 2501, 2502, 2503, 2504, 2505, 2506, 2507, 2508, 2509, 2510, 2511, 2512, 2513, 2514, 2515, 2516, 2517, 2518, 2519, 2520, 2521, 2522, 2523, 2524, 2525, 2526, 2527, 2528, 2529, 2530, 2531, 2532, 2533, 2534, 2535, 2536, 2537, 2538, 2539, 2540, 2541, 2542, 2543, 2544, 2545, 2546, 2547, 2548, 2549, 2550, 2551, 2552, 2553, 2554, 2555, 2556, 2557, 2558, 2559, 2560, 2561, 2562, 2563, 2564, 2565, 2566, 2567, 2568, 2569, 2570, 2571, 2572, 2573, 2574, 2575, 2576, 2577, 2578, 2579, 2580, 2581, 2582, 2583, 2584, 2585, 2586, 2587, 2588, 2589, 2590, 2591, 2592, 2593, 2594, 2595, 2596, 2597, 2598, 2599, 2600, 2601, 2602, 2603, 2604, 2605, 2606, 2607, 2608, 2609, 2610, 2611, 2612, 2613, 2614, 2615, 2616, 2617, 2618, 2619, 2620, 2621, 2622, 2623, 2624, 2625, 2626, 2627, 2628, 2629, 2630, 2631, 2632, 2633, 2634, 2635, 2636, 2637, 2638, 2639,
@yratof
yratof / functions.php
Created March 10, 2015 14:37
ACF OEmbed with thumbnails
<?php
/* Pull apart OEmbed video link to get thumbnails out*/
function get_video_thumbnail_uri( $video_uri ) {
$thumbnail_uri = '';
// determine the type of video and the video id
$video = parse_video_uri( $video_uri );
// get youtube thumbnail
@yratof
yratof / brands.php
Created September 20, 2019 09:20
Create brand taxonomy in Woocommerce
<?php
/**
* Plugin Name: Brand taxonomy
* Plugin URI: https://drivdigital.no
* Description: Force a brand taxonomy to thrive
* Version: 1.0.0
*/
class brand_taxonomy {
// Nope. brand is still a taxonomy