Skip to content

Instantly share code, notes, and snippets.

@ajithrn
ajithrn / .htaccess
Last active August 29, 2015 14:27
Web: Referral Spam
## SITE REFERRER BANNING
RewriteCond %{HTTP_REFERER} floating-share-buttons.com [NC,OR]
RewriteCond %{HTTP_REFERER} floating-share-buttons.com
RewriteRule .* - [F]
@ajithrn
ajithrn / wp-query-order.php
Created August 2, 2015 18:07
WP: Order by multiple meta keys in WP Query
<?php
/**
* This will allow to sort/filter according to different meta key values
* ref: https://mathieuhays.co.uk/order-by-multiple-post-meta-in-wp-query/
*
*/
$args = array(
'post_type' => 'my_post_type',
'posts_per_page' => 10,
@ajithrn
ajithrn / wp-acfrep.php
Last active August 29, 2015 14:22
WordPress: ACF Repeater
<?php if( have_rows('repeater_field_name') ): // check if the repeater field has rows of data ?>
<?php while ( have_rows('repeater_field_name') ) : the_row(); // loop through the rows of data ?>
<?php $foo = get_sub_field('sub_field_name'); // getting a sub field value ?>
<?php endwhile; ?>
<?php else: // no rows found ?>
@ajithrn
ajithrn / auth-url-rewrite.php
Created May 31, 2015 08:19
WordPress: rewrite wp author url
<?php
/**
* author base url rewrire
*
*/
function wp_author_base() {
global $wp_rewrite;
$author_slug = 'user-profile'; // change slug name here
$wp_rewrite->author_base = $author_slug;
}
@ajithrn
ajithrn / soil-nav walker.php
Last active April 20, 2017 02:31
WordPress: Soli Nav walker Modified
<?php
/*
* Modified soil nav walker to add the missing dropdown to the parent li of the ul.sub-menu
*/
namespace Roots\Soil\Nav;
use Roots\Soil\Utils;
/**
@ajithrn
ajithrn / emails.txt
Created April 30, 2015 21:30
Regex: Search emails
[a-zA-Z0-9.!#$%&'*+-/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*
@ajithrn
ajithrn / node-commands.sh
Last active August 29, 2015 14:19
Node: Commands
/**
* Some hacks and code snippets to make nodejs working smoothy on Ubuntu 14.04 / Elementary Freya 0.3
**/
/**
* nodejs installation from latest ppa
* ref: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-an-ubuntu-14-04-server
*/
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install nodejs
sudo apt-get install build-essential
@ajithrn
ajithrn / woo-item.php
Last active August 29, 2015 14:18
Wordpress: Woocommerce items in cart and total
/**
* items to display total number of items and cost
* ref: https://gist.github.com/mikejolley/2044101
*/
<a class="cart-contents"
href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf (_n( '%d item', '%d items', WC()->cart->cart_contents_count ), WC()->cart->cart_contents_count ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
@ajithrn
ajithrn / admin-css.php
Last active August 29, 2015 14:18
Wordpress: admin css
/**
* custom admin css
* code for sage theme: https://roots.io/sage/
* include this snippet in lib/assets.php
*/
function load_custom_wp_admin_style() {
wp_register_style( 'custom_wp_admin_css', asset_path('styles/admin-style.css'), false, '1.0.0' );
wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\load_custom_wp_admin_style' );
@ajithrn
ajithrn / add-google-fonts.php
Last active August 18, 2016 22:47
WordPress: Google Fonts
/**
* Manage google fonts of load_google_font()
* set GOOGLE_FONTS constant in config.php
* for roots.io, Sage wp theme, place this code in lib/extras.php
*/
function load_google_fonts() {
if( ! defined( 'GOOGLE_FONTS' ) ) return;
echo '<link href="//fonts.googleapis.com/css?family=' . GOOGLE_FONTS . '" rel="stylesheet" type="text/css" />'."\n";