Skip to content

Instantly share code, notes, and snippets.

View omniacode's full-sized avatar

Jason Ryan omniacode

View GitHub Profile
@omniacode
omniacode / Add Child Theme JS
Last active November 11, 2016 16:34
WP Child Theme Specific JS
// Load Child Theme Specific JS
function load_child_js_files() {
wp_register_script('filename', get_stylesheet_directory_uri() . '/js/filename.js', array('jquery'), '', true);
wp_enqueue_script('filename');
}
add_action('wp_enqueue_scripts', 'load_child_js_files', 99);
@omniacode
omniacode / Modal
Last active October 8, 2016 16:39
Temp Modal
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.video-modal').magnificPopup({
type: 'iframe',
mainClass: 'mfp-fade',
removalDelay: 160,
preloader: true,
fixedContentPos: false
});
});
// -- WooCommmerce Mods
// Bypass View Cart Page in WooCommerce
function ultimate_redirect_to_checkout() {
global $woocommerce;
// Remove the default `Added to cart` message
wc_clear_notices();
return $woocommerce->cart->get_checkout_url();
}
add_filter ( 'add_to_cart_redirect', 'ultimate_redirect_to_checkout' );
@omniacode
omniacode / custom-taxonomy-shortcode.php
Last active June 16, 2017 20:16
Custom Taxonomy Shortcode - Wordpress
/* Add Custom Taxonomy Shortcode
/*
* Example: [term-list term="taxonomy term here"]
*/
function custom_taxonomy_list_shortcode( $atts ) {
$atts = shortcode_atts( array(
'term' => 'location',
), $atts );
@omniacode
omniacode / favorites-thumb.php
Last active March 4, 2017 15:02
WP Favorites : Thumbnail Favorites
<div id="favorites-post-container">
<?php
$favorites = get_user_favorites();
if ( $favorites ) : // This is important: if an empty array is passed into the WP_Query parameters, all posts will be returned
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; // If you want to include pagination
$favorites_query = new WP_Query(array(
'post_type' => 'post', // If you have multiple post types, pass an array
'posts_per_page' => -1,
'ignore_sticky_posts' => true,
'post__in' => $favorites,
add_action( 'pmxi_saved_post', 'post_saved', 10, 1 );
function post_saved( $id ) {
global $wpdb;
$pass = get_user_meta( $id, 'xfer_user_pass', true );
$wpdb->query( $wpdb->prepare(
"
UPDATE `wp_users`
SET `user_pass` = %s
WHERE `ID` = %d
<?php
/**
* Adds new shortcode "myprefix_say_hello" and registers it to
* the Visual Composer plugin
*
*/
if ( ! class_exists( 'MyPrefix_Say_Hello_Shortcode' ) ) {
class MyPrefix_Say_Hello_Shortcode {
@omniacode
omniacode / wp-remove-yoast.php
Created October 24, 2017 20:54
Remove Yoast Metabox for Everyone Except Admins
// Removes the Yoast Metabox for Roles other then Admins
// Returns true if user has specific role
function check_user_role( $role, $user_id = null ) {
if ( is_numeric( $user_id ) )
$user = get_userdata( $user_id );
else
$user = wp_get_current_user();
if ( empty( $user ) )
return false;
return in_array( $role, (array) $user->roles );
// Remove Taxonomy Slug
add_filter( 'term_link', 'remove_tax_slug_link', 10, 3 );
function remove_tax_slug_link( $link, $term, $taxonomy ) {
if ( $taxonomy !== 'your-taxonomy-name' )
return $link;
return str_replace( 'your-taxonomy-name/', '', $link );
}
add_action('init', 'custom_tax_rewrite_rule', 10, 0);
@omniacode
omniacode / conditionally-enqueue-js.php
Last active November 10, 2022 15:42
Conditionally Enqueue JS per Post Type
add_action( 'wp_enqueue_scripts', 'enqueue_cpt_script' );
function enqueue_cpt_script() {
if ( 'cpt-type' === get_post_type() ) {
if ( wp_script_is( 'file.js', 'enqueued' ) ) {
return;
} else {
wp_register_script( 'file name', get_stylesheet_directory_uri() . '/js/file.js' );
wp_enqueue_script( 'file name' );
}
}