Skip to content

Instantly share code, notes, and snippets.

View developer-anuragsingh's full-sized avatar

Anurag Singh developer-anuragsingh

  • Cendyn
  • Gurugram
View GitHub Profile
@strangerstudios
strangerstudios / coming_soon.php
Created August 13, 2014 15:02
Various options for redirecting to a "Coming Soon" page with WordPress.
/*
1. Create a page called "Coming Soon" with the slug "coming-soon".
If you use something different, be sure to update the code below.
2. Copy just one of the blocks of code below to a custom plugin or your active theme's functions.php.
*/
//redirect non-users to the coming soon page
function coming_soon_redirect()
{
@yoren
yoren / main.html
Last active June 12, 2019 08:39
Display WordPress posts with AngularJS and JSON API
<ul>
<li ng-repeat="post in posts">
<a href="{{post.ID}}">
{{post.title}}
</a>
</li>
</ul>
@fuyuko
fuyuko / functions.php
Last active July 21, 2023 13:06
Cheatsheet - WooCommerce Customization in functions.php
//Add a stylesheet after default style.css
wp_enqueue_style( 'my-css', get_template_directory_uri() . 'my-css.css', array('themename-style'));
//WooCommerce - Sort products by SKU
add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_catalog_orderby');
function custom_woocommerce_catalog_orderby( $args ) {
$args['meta_key'] = '_sku';
$args['orderby'] = 'meta_value';
$args['order'] = 'asc';
return $args;
@developer-anuragsingh
developer-anuragsingh / Find all Prime numbers in a given range through PHP
Created July 4, 2015 13:22
Find all the Prime numbers with the PHP function
<?php
function find_prime_nums($start, $end){
for($i=$start; $i<=$end; $i++){
$counter = 0;
for($j=1; $j<=$i; $j++){
if($i%$j == 0){
$counter++;
}
@Jerry0022
Jerry0022 / PHP Google oAuth2.php
Last active February 27, 2021 22:37
Google oAuth2, sign up, sign in, logout and show user data. Need to set REDIRECT_URL from google developer console and the https://github.com/google/google-api-php-client cloned in the web directory.
<?php
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
$google_redirect_url = 'REDIRECT_URL';
//start session
session_start();
@woogists
woogists / wc-show-cart-contents-total.php
Last active October 26, 2021 20:29
[Theming Snippets] Show cart contents / total
// Use in conjunction with https://gist.github.com/woogists/c0a86397015b88f4ca722782a724ff6c
<a class="cart-customlocation" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf ( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
@woogists
woogists / wc-show-cart-contents-total-ajax.php
Last active December 31, 2023 10:08
[Theming Snippets] Show cart contents / total Ajax
/**
* Show cart contents / total Ajax
*/
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
@mtx-z
mtx-z / wp-bootstrap4.4-pagination.php
Last active January 16, 2025 16:15
Wordpress 5.4 Bootstrap 4.4 pagination (with custom WP_Query() and global $wp_query support) (UPDATED for Bootstrap 5: https://gist.github.com/mtx-z/af85d3abd4c19a84a9713e69956e1507)
<?php
/**
* @param WP_Query|null $wp_query
* @param bool $echo
* @param array $params
*
* @return string|null
*
* UPDATE for Bootstrap 5.0: https://gist.github.com/mtx-z/af85d3abd4c19a84a9713e69956e1507
*
@developer-anuragsingh
developer-anuragsingh / Setup cookie from browser for testing or demo purpose
Created May 10, 2018 09:31
Setup cookie from browser for testing or demo purpose
@developer-anuragsingh
developer-anuragsingh / Display error reporting on dev environment
Created August 3, 2018 05:21
Add in the very first line of your functions.php or header.php file
if ( isset( $_REQUEST['dev'] ) && 1 === intval( $_REQUEST['dev'] ) ) {
error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
}
// How to Use = Add '?dev=1' in url string