Skip to content

Instantly share code, notes, and snippets.

@ajithrn
ajithrn / is_child.php
Last active August 29, 2015 14:16
WordPress: Check if a page is child of another
/**
* Check if a page is child of another
* Ref: http://bavotasan.com/2011/is_child-conditional-function-for-wordpress/
*
* @param mixed $page_id_or_slug Provide the parent ID or Slug
* @return bool Whether the page is child or not of the given parent
*/
function is_child( $page_id_or_slug )
{
global $post;
@ajithrn
ajithrn / box-shadow.html
Last active August 29, 2015 14:16 — forked from ocean90/box-shadow.html
CSS: box-shadows
<!DOCTYPE html>
<html>
<head>
<title>Box Shadow</title>
<style>
.box {
height: 150px;
width: 300px;
margin: 20px;
@ajithrn
ajithrn / remove_wp_font.php
Created March 26, 2015 14:15
WordPress: Remove WP Fonts
/**
* Remove Open Sans that WP adds from frontend
*/
if (!function_exists('remove_wp_open_sans')) :
function remove_wp_open_sans() {
wp_deregister_style( 'open-sans' );
wp_register_style( 'open-sans', false );
}
add_action('wp_enqueue_scripts', 'remove_wp_open_sans');
// Uncomment below to remove from admin
@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";
@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 / 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 / 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 / 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 / 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 / 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;
}