Skip to content

Instantly share code, notes, and snippets.

View FernE97's full-sized avatar

Eric Fernandez FernE97

View GitHub Profile
@FernE97
FernE97 / modernizr-mq.js
Created March 28, 2013 19:15
JS: Modernizr media query
jQuery(document).ready(function ($) {
'use strict';
function doneResizing() {
if (Modernizr.mq('screen and (min-width:768px)')) {
// action for screen widths including and above 768 pixels
} else if (Modernizr.mq('screen and (max-width:767px)')) {
// action for screen widths below 768 pixels
}
}
@FernE97
FernE97 / wp-slides.php
Created April 30, 2013 00:02
PHP: WordPress Slides v2
<?php
$args = array(
'post_type' => 'slides', // custom post type
'orderby' => 'menu_order',
'posts_per_page' => -1
);
$slides = new WP_Query( $args );
if ( $slides->have_posts() ) : $count = 0; ?>
@FernE97
FernE97 / remove-junk.php
Created May 7, 2013 20:46
PHP: WordPress Remove scripts & styles
<?php
// Remove Unecessary Styles & Scripts
function h5bs_remove_junk() {
if ( ! is_admin() ) :
global $WP_Views;
remove_action( 'wp_print_styles', array( $WP_Views, 'add_render_css' ) );
wp_dequeue_style( 'views-pagination-style' ); // plugins/wp-views/embedded/res/css/wpv-pagination.css
wp_dequeue_style( 'date-picker-style' ); // plugins/wp-views/embedded/res/css/datepicker.css
@FernE97
FernE97 / acf-slider.php
Created May 9, 2013 23:45
PHP: WordPress - Advanced Custom Fields Slider
<?php if ( get_field( 'slides' ) ) : // repeater field ?>
<ul class="slider">
<?php while ( the_repeater_field( 'slides' ) ) :
$image = get_sub_field( 'slide' ); // sub-field image ID
$slide = wp_get_attachment_image_src( $image, 'slides' );
$alt = get_post_meta( $image, '_wp_attachment_image_alt', true );
?>
<li><img src="<?php echo $slide[0]; ?>" alt="<?php echo $alt; ?>"></li>
<?php endwhile; ?>
@FernE97
FernE97 / typekit-enqueue.php
Last active April 20, 2019 01:46
PHP: WordPress Typekit wp_enqueue
<?php
function h5bs_enqueue_scripts() {
wp_enqueue_script( 'typekit', '//use.typekit.net/xxxxxxx.js' );
}
add_action( 'wp_enqueue_scripts', 'h5bs_enqueue_scripts' );
function h5bs_typekit_inline() {
@FernE97
FernE97 / excerpt.php
Created May 22, 2013 22:32
PHP: WordPress - Custom Excerpt Length Template Part
<?php
/**
* Custom Excerpt
*
* Needs $word_count set from the template it's being called from
*
* Template Usage:
*
* $word_count = 60;
* get_template_part( 'parts/excerpt' );
@FernE97
FernE97 / tarball.bash
Last active December 18, 2015 04:38
Reminders for creating a tgz file
## Disable mac ._ hidden files
$ export COPYFILE_DISABLE=true
$ cd directory-name
## Filename then path to folder
$ tar -cvzf filename.tgz folder-name
## Period will zip all files from current directory
$ tar -cvzf filename.tgz .
@FernE97
FernE97 / wp_roles.php
Last active December 22, 2015 10:09
WordPress: Display roles and remove by name
<?php
$wp_roles = new WP_Roles();
$names = $wp_roles->get_names();
print_r($names);
$wp_roles->remove_role('role_name');
@FernE97
FernE97 / wp_url.sql
Last active January 6, 2016 23:17
Useful for changing over WordPress urls
-- Avoid updating serialized strings with "NOT LIKE '%{%'"
UPDATE wp_options SET option_value = REPLACE(option_value, '//olddomain.com', '//newdomain.com') WHERE option_value NOT LIKE '%{%';
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '//olddomain.com', '//newdomain.com') WHERE meta_value NOT LIKE '%{%';
UPDATE wp_posts SET post_content = REPLACE(post_content, '//olddomain.com', '//newdomain.com') WHERE post_content NOT LIKE '%{%';
UPDATE wp_posts SET guid = REPLACE(guid, '//olddomain.com', '//newdomain.com') WHERE post_type = 'attachment';
-- File paths
UPDATE wp_options SET option_value = REPLACE(option_value, '/home/old/path', '/home/new/path') WHERE option_value NOT LIKE '%{%';
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '/home/old/path', '/home/new/path') WHERE meta_value NOT LIKE '%{%';
@FernE97
FernE97 / zip-extractor.php
Created February 7, 2014 22:20
Extract zip files from server
<?php
if ( $_GET['file'] ) {
exec( 'unzip '.$_GET['file'] );
}
else {
echo 'Please pass the filename you would like to extract. ex: '.$_SERVER['SCRIPT_URL'].'?file=content.zip';
}
// www.example.com/tgz_extractor.php?file=content.tgz