Skip to content

Instantly share code, notes, and snippets.

🏄
Surfing the www.

Jack Pritchard whatjackhasmade

🏄
Surfing the www.
Block or report user

Report or block whatjackhasmade

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@whatjackhasmade
whatjackhasmade / archived_posts.php
Created Jul 21, 2017
Use The Loop To Create An “Archive” Page Template The problem. As noted in the previous hack, a common problem on blogs is that it is hard for readers to find content published a while ago. To help my readers finding what they’re looking for, I created a WordPress page template that displays a list of all posts ever published on my blog. You can…
View archived_posts.php
<?php
/*
Template Name: Archives
*/
?>
<?php get_header(); ?>
<h2><?php $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
if (0 < $numposts) $numposts = number_format($numposts); ?>
@whatjackhasmade
whatjackhasmade / posts_last_year.php
Created Jul 21, 2017
Display Posts Published One Year Ago
View posts_last_year.php
<?php
$current_day = date('j');
$last_year = date('Y')-1;
query_posts('day='.$current_day.'&year='.$last_year);
if (have_posts()):
while (have_posts()) : the_post();
the_title();
the_excerpt();
endwhile;
endif;
@whatjackhasmade
whatjackhasmade / posts_with_custom_value.php
Created Jul 21, 2017
Get Posts With A Specific Custom Field And Specific Value
View posts_with_custom_value.php
<?php query_posts('meta_key=review_type&meta_value=movie'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
@whatjackhasmade
whatjackhasmade / exclude_posted_posts.php
Created Jul 21, 2017
Use More Than One Loop On A Page, Without Printing Duplicate Posts
View exclude_posted_posts.php
<?php
query_posts('showposts=8');
$ids = array();
while (have_posts()) : the_post();
$ids[] = get_the_ID();
the_title();
the_content();
endwhile;
?>
@whatjackhasmade
whatjackhasmade / post_dates.php
Created Jul 21, 2017
Get Posts Published Between Two Dates The loop and the query_posts() WordPress function allow you to easily retrieve a list of posts published in a specific week or month. Unfortunately, getting posts published between, for example, March 17 and May 3 isn’t that easy. Let’s solve this problem.
View post_dates.php
<?php
function filter_where($where = '') {
$where .= " AND post_date >= '2009-03-17' AND post_date <= '2009-05-03'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);
while (have_posts()) :
the_post();
the_content();
@whatjackhasmade
whatjackhasmade / functions.php
Last active Jun 6, 2017
Allow SVG files to be uploaded to the media library
View functions.php
// Allow SVG files to be uploaded to the media library
add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
global $wp_version;
if ( $wp_version !== '4.7.1' ) {
return $data;
}
$filetype = wp_check_filetype( $filename, $mimes );
@whatjackhasmade
whatjackhasmade / functions.php
Created Jun 5, 2017
Include additional pages to wordpress admin dashboard
View functions.php
function register_my_custom_menu_page() {
add_menu_page( 'Page Title', 'Menu Title', 'manage_options', '../wp-content/themes/index.html', '', 'dashicons-book', 3 );
}
add_action( 'admin_menu', 'register_my_custom_menu_page' );
@whatjackhasmade
whatjackhasmade / functions.php
Created Jun 5, 2017
functions.php - Remove JQuery/Migrate and WP Embed
View functions.php
// Remove jQuery Migrate Script from header and Load jQuery from Google API
function crunchify_stop_loading_wp_embed_and_jquery() {
if (!is_admin()) {
wp_deregister_script('wp-embed');
wp_deregister_script('jquery'); // Bonus: remove jquery too if it's not required
}
}
add_action('init', 'crunchify_stop_loading_wp_embed_and_jquery');
@whatjackhasmade
whatjackhasmade / functions.php
Created Jun 5, 2017
functions.php - Remove WP Emoji
View functions.php
// Remove WP Emoji
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
View media-queries.scss
/*/////////////////////////////////////////
/// MEDIA QUERIES
*/////////////////////////////////////////
/**
* Mixins for defining media queries. These mixins should always be used
* to define media query breakpoints.
*/
@mixin bp-min-width($width) {
You can’t perform that action at this time.