Skip to content

Instantly share code, notes, and snippets.

View hearvox's full-sized avatar

Barrett Golding hearvox

View GitHub Profile
@hearvox
hearvox / kuhf_splashscreening.php
Created April 5, 2011 22:01
Splashscreening: for KUHF.org Pubradio Pledge Drive: Here's a bit of PHP kit my associate here wrote that you guys might find useful.. we put this into our generic header include for duration of the fund drive, so pretty much every page on kuhf.org will
<?php
/*
Splashscreening: for KUHF.org Pubradio Pledge Drive:
*/
// Splash Page Display for Campaign
$current = time();
if ($current <= mktime(5, 0, 0, 4, 4, 2011) || $current >= mktime (12, 0, 0, 4, 15, 2011))
//if current time is earlier than 5am on 4/4/2011, or later than noon on 4/15/2011, then ignore this code
{
@hearvox
hearvox / twitter_chat_archive.php
Created April 6, 2011 13:41
Archive tweets from a weekly Twitter chat. In this case, chat hashtag is #pubmedia (Mon 8p ET). Uses Twitter Search API and WordPress function: wp_remote_get().
<?php
/*
Twitter Chat Archive:
Get hashtag results from Twitter Search API (in JSON) for a weekly chat.
API takes date range via values: 'since' thru 'until' (YYYY-MM-DD).
API limits: 1 page per request, 100 results per page, 1500 total results: <7 days old.
Script below: Repeats page requests until no results found w/in date-range.
Then gathers only those results w/in specified timestamp range.
Then sort results from oldest to newest.
@hearvox
hearvox / wp-pages-dropdown-widget.php
Created December 2, 2014 16:15
WordPress Pages Dropdown Widget
/* Pages dropdown widget" */
// Based on WP_Widget_Pages class in /wp-includes/default-widgets.php
class Hearvox_Widget_Pages_Dropdown extends WP_Widget {
/**
* Register widget with WordPress.
*/
function __construct() {
parent::__construct(
'hearvox_pages_dropdown', // Base ID
@hearvox
hearvox / WP-social-meta.php
Last active May 7, 2019 01:35
Change a WordPress site's homepage default social meta added by the Jetpack plugin for Facebook's Open Graph and Twitter Card tags.
<?php
function hearvox_social_meta( $tags ) {
if ( is_home() || is_front_page() ) {
// Remove the default blank tags added by Jetpack
unset( $tags['og:description'] );
unset( $tags['og:image'] );
unset( $tags['twitter:site'] );
unset( $tags['og:title'] );
unset( $tags['og:url'] );
@hearvox
hearvox / wp_vers_filemod.php
Last active January 11, 2017 18:28
Create version number for WordPress script registration, using filemod or WP vers
<?php
/**
* Use filemod timestamp for version number.
*
* For setting cache-busting version number in script registrations.
* wp_register_script( 'handle', $file_url, array(), filemod_vers( $file_path ) );
*
* @param string $path Path of script/style file
* @return string $vers File-modification timestamp or WordPress version
*/
<?php
/* Update postdate for all post in a category */
// Get IDs of all posts in a category.
$args = array(
'category_name' => 'cat-name',
'fields' => 'ids',
);
$query = new WP_Query($args);
// Update meta for all IDs.
@hearvox
hearvox / wp-debug.php
Created February 16, 2017 16:55
WordPress PHP debug global variable settings
<?php
/* WordPress debug globals (goes in wp-config.php).
* For Dev sites only!
* @ link https://premium.wpmudev.org/blog/debugging-wordpress-how-to-use-wp_debug/
*/
// Turn debugging on.
define( 'WP_DEBUG', true );
// Log PHP error messages to file: /wp-content/debug.log
define( 'WP_DEBUG_LOG', true );
@hearvox
hearvox / wp-list-attachments.php
Created February 18, 2017 04:14
List all images in all sizes in WordPress Media Library.
<?php
$query_images_args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$query_images = new WP_Query( $query_images_args );
$image_sizes = get_intermediate_image_sizes();
$image_sizes[] = 'full';
@hearvox
hearvox / yoast_filter_primary_tax.php
Last active April 19, 2017 15:32
Use Yoast SEO (WordPress plugin) Primary Category only on Category taxonomy.
<?php
/* Use Yoast SEO's Primary Category feature only on Categories. */
function myprefix_yoast_primary_tax( $all_taxonomies ) {
$args = array( 'name' => 'category' );
$all_taxonomies = get_taxonomies( $args, 'objects' );
return $all_taxonomies;
}
add_filter('wpseo_primary_term_taxonomies', 'myprefix_yoast_primary_tax' );
?>