Skip to content

Instantly share code, notes, and snippets.

View khromov's full-sized avatar

Stanislav Khromov khromov

View GitHub Profile
@khromov
khromov / 404.php
Created May 24, 2016 20:28
Set a page with slug "404-error" as your 404 page in WordPress
<?php get_header(); ?>
<div class="container-fluid">
<div class="content">
<main role='main'>
<?php
$query_404 = new WP_Query(array(
'posts_per_page' => 1,
'post_type' => 'page',
'post_name' => '404-error'
));
@khromov
khromov / deploy.php
Created June 8, 2016 07:28
Deploy WordPress with Deployer on EasyEngine
<?php
require 'recipe/common.php';
// Set configurations
set('repository', 'ssh://gogs@git.server.com:22/user/repo.git');
set('shared_files', ['public/wp-config.php']);
set('shared_dirs', ['public/wp-content/uploads']);
set('writable_dirs', []);
set('keep_releases', 10);
set('composer_command', 'composer');
@khromov
khromov / gist:6398615
Created August 31, 2013 14:36
Shairport startup script for Raspberry Pi. See full tutorial: http://snippets.khromov.se/raspberry-pi-shairport-build-instructions/
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $networking
# Required-Stop: $remote_fs $networking
# Should-Start: pulseaudio alsa-utils hostname
# Should-Stop: pulseaudio alsa-utils hostname
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
@khromov
khromov / gist:10502980
Created April 11, 2014 21:27
Adding custom shortcodes to Contact Form 7
<?php
/*
Plugin Name: Contact Form 7 Post Title shortcode
Plugin URI:
Description: Use in form: [post_title thetitle] - use in email (to get value): [thetitle]
Version: 2014.04.07
Author: khromov
Author URI: http://profiles.wordpress.org/khromov/
License: GPL2
*/
@khromov
khromov / include_templates.php
Created October 27, 2014 23:27
Include theme templates from plugin, WordPress
<?php
/**
* Helper function for including templates
*
* @param $template
*/
function include_template($template, $args)
{
extract($args);
@khromov
khromov / prerender.php
Created August 23, 2015 23:08
WordPress Instant Articles - Prerender specific pages - https://wordpress.org/plugins/instant-articles/
<?php
add_filter('wpinstant_prerendered_urls', function($urls) {
if ( is_front_page() ) {
$posts = array( 1,2,3);
foreach($posts as $post) {
$permalink = get_permalink( $post );
if($permalink) {
$urls[] = $permalink;
}
}
@khromov
khromov / rock-paper-scissors-js.html
Created September 3, 2017 15:52
Rock, Paper, Scissors - JS game
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width">
<title>Rock, Paper, Scissors</title>
<style>
*{margin:0;padding:0;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}::selection{background:#fb9fe5;text-shadow:none}a{color:#0088CC;text-decoration:none;outline:0}a:hover{color:#005580}a img{border:none}img{max-width:100%}html{font-size:100%}body{padding:5%;font:300 1.25em/1.6 monospace;background:#fff;color:#000;}h1{font-family:"Helvetica Neue",sans-serif;line-height:1;font-weight:300;margin-bottom:1em;}.game{padding:2em;background:#eee;}
@khromov
khromov / prerender-by-meta.php
Last active September 1, 2017 07:41
WordPress Instant Articles - Prerender pages by meta value - https://wordpress.org/plugins/instant-articles/
<?php
add_filter('wpinstant_prerendered_urls', function($urls) {
if ( is_home() ) {
$args = array(
'meta_key'=> 'prefetch_on_home',
'meta_value' => true
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
foreach( $query->posts as $post ) {
@khromov
khromov / bootstrap-3-grid.css
Last active June 12, 2017 16:05
Bootstrap 3 Grid (Without the rest of the framework).
/*!
* Grid portion of Bootstrap under sc- namespace.
* Classes:
* sc-container-fluid, sc-row, sc-col-X-Y (like regular B3)
*
* For more info, see:
* http://snippets.khromov.se/decoupled-bootstrap-3-grid/
*
* Bootstrap v3.2.0 (http://getbootstrap.com)
* Copyright 2011-2014 Twitter, Inc.
@khromov
khromov / wordpress-taxonomy-query-acf-taxonomy-field-example.php
Last active April 14, 2017 05:22
wordpress-taxonomy-query-acf-taxonomy-field-example
$post_id = 1; //Post ID
$post_taxonomies = get_field('assigned-taxonomies', $post_id);
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'your-taxonomy',
'field' => 'term_id',
'terms' => $post_taxonomies