Skip to content

Instantly share code, notes, and snippets.

@Narendharr
Narendharr / woocommerce-optimize-scripts.php
Created March 31, 2021 17:18 — forked from DevinWalker/woocommerce-optimize-scripts.php
Only load WooCommerce scripts on shop pages and checkout + cart
/**
* 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' ) );
@Narendharr
Narendharr / honeypot-example.php
Created March 20, 2021 17:06 — forked from andrewlimaza/honeypot-example.php
Simple honeypot for an HTML form using PHP
<?php
//check if form was sent
if($_POST){
$to = 'some@email.com';
$subject = 'Testing HoneyPot';
$header = "From: $name <$name>";
$name = $_POST['name'];
@Narendharr
Narendharr / woo-radio-button.php
Created May 20, 2020 10:38 — forked from jan-koch/woo-radio-button.php
Example implementation of radio buttons as product meta fields, in the "General" tab.
<?php
function prefix_add_radio_buttons() {
$args = array(
'label' => '', // Text in the label in the editor
'class' => 'prefix_radio', // custom class
'style' => '',
'wrapper_class' => '', // custom wrapper class
'value' => '', // if empty, retrieved from meta_value where id is the meta_key
'id' => '', // required, will be used as meta_key for this field
'name' => 'my_radio_buttons', // required if you want only one option to be selected at a time
<?php
/**
* Plugin Name: Custom Fields for WooCommerce
* Description: Add custom fields to WooCommerce products
* Version: 1.0.0
* Author: Gareth Harris
* Author URI: https://pluginrepublic.com/
* Text Domain: cfwc
* WC requires at least: 3.4.0
* WC tested up to: 3.4.2
@Narendharr
Narendharr / search.php
Created April 23, 2020 07:51 — forked from galengidman/search.php
WordPress search form & results for custom post type
<?php
// store the post type from the URL string
$post_type = $_GET['post_type'];
// check to see if there was a post type in the
// URL string and if a results template for that
// post type actually exists
if ( isset( $post_type ) && locate_template( 'search-' . $post_type . '.php' ) ) {
@Narendharr
Narendharr / repeatable-fields-metabox.php
Created April 4, 2020 09:55 — forked from helen/repeatable-fields-metabox.php
Repeating Custom Fields in a Metabox
<?
/**
* Repeatable Custom Fields in a Metabox
* Author: Helen Hou-Sandi
*
* From a bespoke system, so currently not modular - will fix soon
* Note that this particular metadata is saved as one multidimensional array (serialized)
*/
function hhs_get_sample_options() {
@Narendharr
Narendharr / Lazy Image Size
Created April 4, 2020 05:24 — forked from mtinsley/Lazy Image Size
Generate image sizes on the fly for WordPress
/**
* Create an image with the desired size on-the-fly.
*
* @param $image_id
* @param $width
* @param $height
* @param $crop
*
* @return array
*/
@Narendharr
Narendharr / jquery-scroll-bottom.js
Created March 25, 2020 15:29 — forked from toshimaru/jquery-scroll-bottom.js
Detect the scrolling to bottom of the page using jQuery.
$(window).on("scroll", function() {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
// when scroll to bottom of the page
}
});
@Narendharr
Narendharr / Related category posts of current post
Last active February 7, 2020 04:47 — forked from cjmox/Related posts
WordPress: Related Posts based on category of current post
<!-- This code is based on an old post in the WordPress forums: http://wordpress.org/support/topic/passing-current-single_tag_title-as-variable-into-new-wp_query#post-1001978 -->
<div class="related-entries">
<div class="block">
<ul>
<?php
//for use in the loop, list 5 post titles related to first tag on current post
$cats = get_the_category($post->ID);
if ($cats) {
echo '<h3>Related Posts</h3>';
@Narendharr
Narendharr / youtube_id_regex.php
Created January 31, 2020 12:30 — 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