Skip to content

Instantly share code, notes, and snippets.

View santanup789's full-sized avatar

Santanu Patra santanup789

  • Webskitters
  • India
View GitHub Profile
@smonteverdi
smonteverdi / gist:2378216
Created April 13, 2012 16:37
WordPress: Breadcrumbs
<?php
if (function_exists('register_sidebar')) {
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}
@mannieschumpert
mannieschumpert / gist:8334811
Last active August 20, 2023 14:58
Filter the submit button in Gravity Forms to change the <input type="submit> element to a <button> element. There's an example in the Gravity Forms documentation, but it lacks the proper code to show your custom button text, AND removes important attributes like the onclick that prevents multiple clicks. I was trying to solve that.
<?php
// filter the Gravity Forms button type
add_filter("gform_submit_button", "form_submit_button", 10, 2);
function form_submit_button($button, $form){
// The following line is from the Gravity Forms documentation - it doesn't include your custom button text
// return "<button class='button' id='gform_submit_button_{$form["id"]}'>'Submit'</button>";
// This includes your custom button text:
return "<button class='button' id='gform_submit_button_{$form["id"]}'>{$form['button']['text']}</button>";
}
// Oops this strips important stuff
@qutek
qutek / woocommerce-ajax.php
Last active May 27, 2024 16:04
[Wordpress] [Woocommerce] WooCommerce Ajax Handlers
<?php
/**
* WooCommerce Ajax Handlers
*
* Handles AJAX requests via wp_ajax hook (both admin and front-end events)
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/** Frontend AJAX events **************************************************/
@kittenlane
kittenlane / add_currency_code_suffix.php
Created May 3, 2015 22:49
Add currency code as suffix to prices in WooCommerce
//* http://www.codemyownroad.com/add-currency-code-suffix-prices-woocommerce/
// Location: add to functions.php
// Output: displays $0.00 AUD on all pages
function addPriceSuffix($format, $currency_pos) {
switch ( $currency_pos ) {
case 'left' :
$currency = get_woocommerce_currency();
$format = '%1$s%2$s&nbsp;' . $currency;
break;
@shizhua
shizhua / like-it-enqueue.php
Last active September 25, 2023 12:48
Add a like button without a plugin in WordPress
add_action( 'wp_enqueue_scripts', 'pt_like_it_scripts' );
function pt_like_it_scripts() {
if( is_single() ) {
wp_enqueue_style( 'like-it', trailingslashit( plugin_dir_url( __FILE__ ) ).'css/like-it.css' );
if (!wp_script_is( 'jquery', 'enqueued' )) {
wp_enqueue_script( 'jquery' );// Comment this line if you theme has already loaded jQuery
}
wp_enqueue_script( 'like-it', trailingslashit( plugin_dir_url( __FILE__ ) ).'js/like-it.js', array('jquery'), '1.0', true );
@yanknudtskov
yanknudtskov / gravityforms-auto-trigger-next-previous.js
Last active October 7, 2021 20:03
jQuery example to trigger next/previous buttons on GravityForms #gravity-forms
// This is the initial GravityForms binding, it will be lost upon a page change with next/previous
// Thus we make a bind on gform_page_loaded event also
if( jQuery('.custom-form').length > 0 ) {
jQuery('.gfield_radio input[type=radio]').bind("click", function() {
//console.log('Clicked: ' + jQuery( this ).closest('.gform_page').find('.gform_page_footer .gform_next_button.button') );
jQuery(this).closest('.gform_page').find('.gform_page_footer .gform_next_button.button').click();
});
}
jQuery(document).bind('gform_page_loaded', function(event, form_id, current_page){
@mahdi-alavi
mahdi-alavi / gist:9d7752572fed9cedc8b10c6876d1e86a
Last active July 24, 2022 19:12
replace WooCommerce add-to-cart button with download link when product is downloadable & free
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', 'itl_woocommerce_template_single_add_to_cart', 30 );
/*
* replace WooCommerce add-to-cart button with download link when product is downloadable & free
*/
function itl_woocommerce_template_single_add_to_cart() {
global $product;
if ( $product->is_downloadable('yes') ) {
@Niloys7
Niloys7 / gist:17b88d36c1c38844a6cf2127c15dee63
Created February 24, 2017 01:17
Get Product Gallery Images - WooCommerce
<?php
global $product;
$attachment_ids = $product->get_gallery_attachment_ids();
foreach( $attachment_ids as $attachment_id )
{
//Get URL of Gallery Images - default wordpress image sizes
echo $Original_image_url = wp_get_attachment_url( $attachment_id );
echo $full_url = wp_get_attachment_image_src( $attachment_id, 'full' )[0];
echo $medium_url = wp_get_attachment_image_src( $attachment_id, 'medium' )[0];
@hachesilva
hachesilva / functions.php
Created March 14, 2017 18:19 — forked from corsonr/functions.php
Display WooCommerce product variations dropdown select on the shop page
<?php
// Display variations dropdowns on shop page for variable products
add_filter( 'woocommerce_loop_add_to_cart_link', 'woo_display_variation_dropdown_on_shop_page' );
function woo_display_variation_dropdown_on_shop_page() {
global $product;
if( $product->is_type( 'variable' )) {
@deardorffdev
deardorffdev / wordpress-functions.php
Last active November 1, 2024 14:17
Useful Wordpress Functions 1
<!-- What is Functions File in WordPress? -->
<!-- Functions file commonly known as functions.php file is a WordPress theme file.
It comes with all free and premium WordPress themes.
The purpose of this file is to allow theme developers to define theme features and functions. This file acts just like a WordPress plugin and can be used to add your own custom code snippets in WordPress.
You would find many of these code snippets on websites like https://deardorffassociatesweb.wordpress.com/ with instructions telling you to add this code in your theme’s functions.php file or a site-specific WordPress plugin.
Now you may be thinking what’s the difference between a site-specific WordPress plugin and functions.php file? Which one is better?