Skip to content

Instantly share code, notes, and snippets.

View joshapgar's full-sized avatar

Josh Apgar joshapgar

View GitHub Profile
@joshapgar
joshapgar / functions.php
Last active January 30, 2018 15:39
Create angular app at specified URL and allow refresh from within Wordpress
function angular_app_rewrite_rules() {
$angular_app_page_id = 20;
add_rewrite_rule('^angular-app/*', 'index.php?page_id=' . $angular_app_page_id, 'top');
}
add_action('init', 'angular_app_rewrite_rules');
@joshapgar
joshapgar / .htaccess
Created April 10, 2018 19:15
Protect the Wordpress uploads if not logged in.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^.*uploads/.*
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule . /index.php [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
@joshapgar
joshapgar / functions.php
Created April 10, 2018 19:22
Disable WP API
// Disable REST API link tag
remove_action('wp_head', 'rest_output_link_wp_head', 10);
// Disable oEmbed Discovery Links
remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
// Disable REST API link in HTTP headers
remove_action('template_redirect', 'rest_output_link_header', 11, 0);
function restrict_rest_api_to_localhost() {
@joshapgar
joshapgar / git-deployment.md
Created May 7, 2018 15:10 — forked from noelboss/git-deployment.md
Simple automated GIT Deployment using Hooks

Simple automated GIT Deployment using GIT Hooks

Here are the simple steps needed to create a deployment from your lokal GIT repository to a server based on this in-depth tutorial.

How it works

You are developing in a working-copy on your local machine, lets say on the master branch. Most of the time, people would push code to a remote server like github.com or gitlab.com and pull or export it to a production server. Or you use a service like my Deepl.io to act upon a Web-Hook that's triggered that service.

@joshapgar
joshapgar / Bootstrap-4-Breakpoints.txt
Created July 18, 2018 14:47
New bootstrap 4 show hide utilities
Show/hide for breakpoint and down:
hidden-xs-down (hidden-xs) = d-none d-sm-block
hidden-sm-down (hidden-sm hidden-xs) = d-none d-md-block
hidden-md-down (hidden-md hidden-sm hidden-xs) = d-none d-lg-block
hidden-lg-down = d-none d-xl-block
hidden-xl-down (n/a 3.x) = d-none (same as hidden)
Show/hide for breakpoint and up:
hidden-xs-up = d-none (same as hidden)
@joshapgar
joshapgar / acf-search.php
Created September 13, 2018 14:32
ACF to Search Results
// Make the search to index custom
/**
* Extend WordPress search to include custom fields
* http://adambalee.com
*
* Join posts and postmeta tables
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
*/
function cf_search_join( $join ) {
global $wpdb;
@joshapgar
joshapgar / style.css
Created September 14, 2018 13:13
Text with mix-blend-mode background
.bg {
background-image: url('https://images.unsplash.com/photo-1501706362039-c06b2d715385?auto=format&fit=crop&w=1070&q=60&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D');
background-repeat: no-repeat;
background-position: center center;
padding: 100px 50px;
}
.text {
position: relative;
}
@joshapgar
joshapgar / breadcrumbs.php
Created September 24, 2018 13:08
Wordpress Breadcrumbs
/***********************
* BREADCRUMBS
***********************/
function streamlineBreadcrumbs($post, $displayCurrent){
$count = 1;
$postAncestors = get_post_ancestors($post);
$sortedAncestorArray = array();
foreach ($postAncestors as $ancestor){
$sortedAncestorArray[] = $ancestor;
@joshapgar
joshapgar / desktopmenutouch.js
Last active March 5, 2019 15:58
Function for detecting touch device and adding class to menu items when clicked with touch device.
function is_touch_device() {
var prefixes = ' -webkit- -moz- -o- -ms- '.split(' ');
var mq = function(query) {
return window.matchMedia(query).matches;
}
if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
return true;
}
@joshapgar
joshapgar / example-custom-post-type.php
Last active March 14, 2019 01:37
Custom Post Type with all the options.
<?php
if ( ! function_exists('portfolio_post_type') ) :
// Add Portfolio Projects to WordPress
add_action( 'init', 'portfolio_post_type', 0 );
// Register Portfolio Projects Custom Post Type
function portfolio_post_type()
{
$labels = array(