Skip to content

Instantly share code, notes, and snippets.

@aurooba
aurooba / cleanernav.php
Last active February 24, 2016 00:22
A simple function that outputs a cleaner one-level nav with classes intact.
/**
* Returns a cleaner Navigation
*
* Usage:
* <nav id="site-navigation" class="main-navigation" role="navigation">
* <?php cleanernav('primary'); ?>
* </nav>
*
* Output Example:
* <nav id="site-navigation" class="main-navigation" role="navigation">
@aurooba
aurooba / has_post_thumbnail_caption.php
Created May 31, 2016 15:37
Post Thumbnail (Featured Image) Captions in WordPress
/**
* Check if Post Thumbnail (Featured Image) has a caption, return true if it does
*/
function has_post_thumbnail_caption() {
global $post;
$thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail_image = get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment'));
$thumbnail_excerpt = $thumbnail_image[0]->post_excerpt;
@aurooba
aurooba / wpseo-opengraph-coauthor-integration.php
Last active August 26, 2016 02:03
Making Co-author Plus play nice with Yoast SEO Open Graph
/**
* Pulls the correct facebook link for guest authors using
* Co-author Plus. Ideally, need to fix this so it works with empty fields as well.
*/
add_filter('wpseo_opengraph_author_facebook', 'aa_wpseo_facebook');
function aa_wpseo_facebook($fb) {
if(! function_exists('get_coauthors') )
return $fb;
@aurooba
aurooba / entry_meta.php
Last active September 16, 2016 16:35
WordPress - Show updated date as well if post was modified
if ( ! function_exists( 'aa_entrymeta' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author. If post was updated, it also prints
* the date of the update.
*/
function aa_entrymeta() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
$update_time_string = '<time class="updated" datetime="%s">%s</time>';
$time_string = sprintf( $time_string,
@aurooba
aurooba / postnotification.php
Last active June 2, 2017 23:12
Post Notification
<?php
add_action("publish_post", "publication_notification");
//add_action("save_post", "publication_notification");
//add_action ( 'draft_to_publish', 'publication_notification', 10, 3);
function publication_notification($post_id) {
$post = get_post($post_id);
$coauthors = get_coauthors($post_id);
@aurooba
aurooba / breakpointmixin.scss
Last active August 3, 2017 19:14
Custom Breakpoint Mixin
/// This mixin assumes mobile-first coding, and helps you respond to different breakpoints
/// from within each applicable selector.
/// It pulls breakpoints from a map of breakpoints set in _variables.scss ( but provided below in this gist )
/// USAGE:
/// .entry-content {
/// @respond-to(river) {
/// width: 50%
/// }
/// }
@aurooba
aurooba / migratesql.sql
Created October 26, 2017 20:05
SQL query to run when migrating WordPress dbs
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
@aurooba
aurooba / wo_is_role.php
Last active October 17, 2018 17:32
Shortcode for restricting things based on ANY WordPress role
<?php
/**
* Creates a shortcode [wo_is_role] that allows you to restrict anything inside to a particular role or roles.
* To use: [wo_is_role role="subscriber"] Put content here to show subscriber [/wo_is_role]
* To use with multiple roles: [wo_is_role role="contributor,subscriber"] Put content here to show contributors and susbcribers. [/wo_is_role]
*
* Works with ANY role, including all custom roles.
*/
@aurooba
aurooba / nav_social_walker.php
Last active August 4, 2019 00:22
Social Media Navigation Walker
<?php
/**
* Custom Social Media Nav Walker by Aurooba Ahmed
* This uses Font Awesome and adds in the correct icon by detecting the URL of the menu item.
* You can use this by doing a custom wp_nav_menu query:
* wp_nav_menu(array('items_wrap'=> '%3$s', 'walker' => new WO_Nav_Social_Walker(), 'container'=>false, 'menu_class' => '', 'theme_location'=>'social', 'fallback_cb'=>false ));
*
*/
class WO_Nav_Social_Walker extends Walker_Nav_Menu {
@aurooba
aurooba / gulpfile.js
Last active June 26, 2020 22:30
A basic Gulp.js file for WordPress Theme Development
/**
* Gulpfile.
*
* Workflow Supercharged
*
* Implements:
* 1. Live reloads browser with BrowserSync.
* 2. CSS: SCSS to CSS conversion, error catching, autoprefixing, sourcemaps, and CSS minification
* 3. JS: Concatenates & uglifies Vendor and Custom JS files.
* 4. Images: Minifies PNG, JPEG, GIF and SVG images.