Skip to content

Instantly share code, notes, and snippets.

@tjhole
tjhole / WORDPRESS: Custom Post Type Front Page - 2014 (b)
Created July 23, 2014 11:07
WORDPRESS: Custom Post Type Front Page - 2014 (b)
function enable_front_page_stacks( $query ){
if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
$query->query_vars['post_type'] = array( 'page', 'stack' );
}
add_action( 'pre_get_posts', 'enable_front_page_stacks' );
@tjhole
tjhole / WORDPRESS: Dynamic SiteURL
Created August 12, 2014 07:49
WORDPRESS: Dynamic SiteURL
define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] );
define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME'] );
@tjhole
tjhole / ACF: Options Page Enable
Created August 14, 2014 10:22
ACF: Options Page Enable
if(function_exists('acf_add_options_page')) {
acf_add_options_page();
acf_add_options_sub_page('Header');
acf_add_options_sub_page('Footer');
}
@tjhole
tjhole / ACF: Create Menu
Created August 14, 2014 10:32
ACF: Create Menu
<?php
// check if the repeater field has rows of data
if( have_rows('main_menu','options') ): ?>
<ul>
<?php
// loop through the rows of data
while ( have_rows('main_menu','options') ) : the_row();
$link = get_sub_field('page');
@tjhole
tjhole / WORDPRESS: Jetpack Subscription Form
Last active August 29, 2015 14:05
WORDPRESS: Jetpack Subscription
<?php $status = isset( $_REQUEST['subscribe'] ) ? $_REQUEST['subscribe'] : false; ?>
<?php if ( $status == 'invalid_email' ) : ?>
<p>You have entered an invalid e-mail, please try again!</p>
<?php elseif ( $status == 'success' ) : ?>
<p>Thank you for subscribing! Please check your e-mail to confirm.</p>
<?php else : ?>
<form method="POST">
<input type="hidden" name="my-form-action" value="subscribe" />
<input name="my-email" value="" placeholder="Enter your e-mail" />
<input type="submit" />
@tjhole
tjhole / CSS: Remove iOS input formatting
Created September 5, 2014 11:32
CSS: Remove iOS input formatting
input {
-webkit-appearance: none;
@include border-radius(0);
border-radius: none;
-webkit-border-radius:0px;
}
@tjhole
tjhole / gist:205630e73a76f826733f
Created September 11, 2014 09:08
WORDPRESS: Zip
function zip_gallery()
{
global $post;
$images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_mime_type' => 'image', ));
if ($images) {
$save = $post->post_title;
$zip = new ZipArchive;
if ($zip->open($save . '.zip', ZIPARCHIVE::CREATE) === true) {
@tjhole
tjhole / WORDPRESS : Remove parent from attachment URL
Created September 22, 2014 19:19
WORDPRESS : Remove parent from attachment URL
function wpa60888_attachment_link( $link, $id ){
return home_url() . '/?attachment_id=' . $id;
}
add_filter( 'attachment_link', 'wpa60888_attachment_link', 10, 2 );
@tjhole
tjhole / WORDPRESS: Jquery Custom
Created October 2, 2014 10:13
WORDPRESS: Jquery Custom
wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
wp_enqueue_script('jquery');
@tjhole
tjhole / ACF: Random Image
Last active August 29, 2015 14:08
ACF: Random Image
<?php
$gallery = get_field('images');
$rand = array_rand($gallery, 1);
if( $gallery ): ?>
<img src="<?php echo $gallery[$rand]['sizes']['large']; ?>" alt="<?php echo $gallery[$rand]['alt']; ?>" />
<?php endif; ?>