Skip to content

Instantly share code, notes, and snippets.

@wisecrab
wisecrab / mixins.scss
Last active November 21, 2024 16:28
A collection of useful SCSS mixins.
/***********************************************
Gradients
***********************************************/
@mixin gradient($from, $to) {
background: -webkit-gradient(linear, left top, left bottom, from($from), to($to));
background: -moz-linear-gradient(top, $from, $to);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}');
}
//Usage
<?php
function seoFriendly($string, $separator) {
//Only accept dashes or underscores
if( $separator == "-" || $separator == "_" ) {
$separator = $separator;
} else {
$separator = "-";
}
@wisecrab
wisecrab / custom-fields-and-taxonomies.php
Last active August 27, 2015 15:41
Easy to use functions for getting access to custom meta data for posts and custom posts.
/*****************************************************
*** Get all taxonomy terms for a post ***
*****************************************************/
get_the_term_list( $post->ID, 'taxonomy_name' ); //Returns links
get_the_term_list( $post->ID, 'taxonomy_name', '', ', ', '' ); //Returns links separated by commas
strip_tags(get_the_term_list( $post->ID, 'taxonomy_name' )); //Returns text
/*****************************************************
*** Get custom fields for a post ***
@wisecrab
wisecrab / string-split-by-word-after-x-characters.php
Last active September 2, 2015 20:55
Split a string by word after $x amount of characters
<?php
function splitStringByWords($x, $string) {
//Convert the string
$converted_string = explode( "\n", wordwrap( $string, $x));
//Return the array of split strings
return $converted_string;
}
//Number of characters the split will occur after
<?php
/***********************************************************************************
These are examples and references for the WooCommerce Order Item meta data hooks
that is displayed in the admin side of WordPress when viewing a customer's order.
***********************************************************************************/
//Do Something before the order item's meta data
do_action( 'woocommerce_before_order_itemmeta', $item_id, $item, $_product );
//Do Something after the order item's meta data
//echo the current filename
echo basename(__FILE__);
//echo current filename without extension
echo basename(__FILE__, '.php');
//Echo the current URL
echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
@wisecrab
wisecrab / wordpress-add-term-meta.php
Last active December 24, 2015 17:18
Term Meta in WordPress 4.4
<?php
/*
The functions below will work in wordpress 4.4 and greater.
These functions allow you to add, get, and update meta data for terms/taxonomies.
*/
/*
*** Add Meta Data To A Term
@wisecrab
wisecrab / prepare-url.php
Created December 21, 2015 18:50
Simple function to prepare URL's with either http or https
<?php
function prepare_url($string) {
//Check if the string starts with http or https
if (substr($string, 0, 7) == "http://" OR substr($string, 0, 8) == "https://") {
$url = $string;
} else {
//Remove any presence of http:// or https:// from the link
$string = str_replace("://", "", $string);
<?php
function checkForRedirects($URL) {
$ch = curl_init($URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_exec($ch);
$original_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
@wisecrab
wisecrab / useful-linux-commands.txt
Last active February 17, 2016 13:56
A collection of useful terminal commands to use in linux.
//Check if packages are installed
dpkg --get-selections | grep [package_name]
//Show a list of files and directories in the current directory.
ls
//Show file permissions
ls -l /avr/www/html/index.php
//Edit a file