Skip to content

Instantly share code, notes, and snippets.

@chillbits-legacy
chillbits-legacy / your-plugin-main-file.php
Last active January 27, 2016 18:56
Multiple categories rewrite rules in WordPress. Example: /cat/child-cat/grandchild-cat/cpt-name/
<?php
class Your_Plugin {
/**
* Post Type slug modification
*
* @since 1.0.0
* @return null
*/
function modifySlug($link, $post)
{
@chillbits-legacy
chillbits-legacy / flattern.php
Created January 27, 2016 19:22
Convert multi dimension array to 1 dimension array
<?php
/**
* Convert multi dimension array to 1 dimension array. Use this function when you need to convert
* wpdb results array to one dimension array
*
* @since 1.4.1
* @return string
*/
function flatten($v) {
if(count($v, COUNT_RECURSIVE) !== count($v)) {
—– BEGIN LICENSE —–
Michael Barnes
Single User License
EA7E-821385
8A353C41 872A0D5C DF9B2950 AFF6F667
C458EA6D 8EA3C286 98D1D650 131A97AB
AA919AEC EF20E143 B361B1E7 4C8B7F04
B085E65E 2F5F5360 8489D422 FB8FC1AA
93F6323C FD7F7544 3F39C318 D95E6480
FCCC7561 8A4A1741 68FA4223 ADCEDE07
@chillbits-legacy
chillbits-legacy / countrycode.php
Last active July 15, 2016 08:16
Get country code from phone number
<?php
function getCountryCode($phoneNumber) {
// get your list of country codes
$countries = getCountries();
$countries = array(array("US","1","US (+1)"),array("GB","44","GB (+44)")) + $countries;
foreach( $countries as $country )
{
if ( substr( $phoneNumber, 0, strlen( '+'.$country[1] ) ) == '+'.$country[1] )
{
// match
/** Viet Artisans fixes **/
// Dynamic menu activation
var vaj = jQuery.noConflict();
vaj(document).ready(function(){
currentURL = document.location.href;
vaj('.accordion-header a').each(function(index){
if(vaj(this).attr('href') == currentURL)
{
activeSideMenu(vaj(this));
return;
@chillbits-legacy
chillbits-legacy / category-sidebar-in-single.php
Created November 10, 2016 05:18
Display different sidebar based on category of single post
<?php
if(is_single()) {
$categories = new WPSEO_Primary_Term('category', get_the_ID());
$category_id = $categories->get_primary_term();
$category = &get_category($category_id);
switch($category->slug) {
case 'blog':
@chillbits-legacy
chillbits-legacy / manifest.json
Created November 10, 2016 05:32
Config js in manifest.json file
"main.js": {
"files": [
"scripts/main.js"
],
"main": true
},
"main.js": {
"files": [
"scripts/test-1.js", // đặt lên trước thì nó sẽ load trước.
"scripts/main.js",
"scripts/test-2.js" // đặt sau thì nó sẽ load sau.
],
"main": true
},
@chillbits-legacy
chillbits-legacy / .htaccess
Created November 10, 2016 07:41
Wordpress .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
@chillbits-legacy
chillbits-legacy / install-wp-cli.sh
Created November 17, 2016 10:45
Install wp-cli
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp