Skip to content

Instantly share code, notes, and snippets.

@galengidman
galengidman / functions.php
Last active Jan 7, 2021
Adding Static Menu Items to wp_nav_menu()
View functions.php
<?php
function my_nav_wrap() {
// default value of 'items_wrap' is <ul id="%1$s" class="%2$s">%3$s</ul>'
// open the <ul>, set 'menu_class' and 'menu_id' values
$wrap = '<ul id="%1$s" class="%2$s">';
// get nav items as configured in /wp-admin/
$wrap .= '%3$s';
@galengidman
galengidman / search.php
Last active Dec 9, 2020
WordPress search form & results for custom post type
View search.php
<?php
// check to see if there is a post type in the URL
if ( isset( $_GET['post_type'] ) && $_GET['post_type'] ) {
// save it for later
$post_type = $_GET['post_type'];
// check to see if a search template exists
if ( locate_template( 'search-' . $post_type . '.php' ) ) {
@galengidman
galengidman / index.php
Created Mar 28, 2014
get ACF image size URL by ID
View index.php
<?php
// first, get the image ID returned by ACF
$image_id = get_field('my_image_field');
// and the image size you want to return
$image_size = 'thumbnail';
// use wp_get_attachment_image_src to return an array containing the image
// we'll pass in the $image_id in the first parameter
@galengidman
galengidman / index.html
Last active Nov 26, 2020
`display: table` sticky footer trick
View index.html
<header class="page-row">
<h1>Site Title</h1>
</header>
<main class="page-row page-row-expanded">
<p>Page content goes here.</p>
</main>
<footer class="page-row">
<p>Copyright, blah blah blah.</p>
@galengidman
galengidman / user.php
Last active Sep 23, 2020
Example WordPress user model
View user.php
<?php
class User {
public $ID;
public $_user;
public $attributes = [
'description',
View bb2gh.sh
#!/bin/bash
set -e
repos=("repo-name" "another-repo")
for repo in ${repos[@]}; do
echo
echo "* Processing $repo..."
echo
git clone --bare git@bitbucket.org:ORG/$repo.git
cd $repo.git
echo
@galengidman
galengidman / index.php
Created Mar 28, 2014
get ACF image size URL by image object
View index.php
<?php
// first, get the image object returned by ACF
$image_object = get_field('my_image_field');
// and the image size you want to return
$image_size = 'thumbnail';
// now, we'll exctract the image URL from $image_object
$image_url = $image_object['sizes'][$image_size];
@galengidman
galengidman / youtube-id-from-url.php
Created Jan 23, 2017
Get a YouTube video ID from any format of YouTube URL.
View youtube-id-from-url.php
<?php
function youtube_id_from_url( $url = null ) {
if ( ! $url || ( stripos( $url, 'youtube.com' ) === false && stripos( $url, 'youtu.be' ) === false ) ) {
return false;
}
$parsed_url = parse_url( $url );
@galengidman
galengidman / functions.php
Last active Jul 17, 2017
Check if WooCommerce cart has items, add link to have if it does
View functions.php
<?php
function my_nav_wrap() {
// checks if there is an item in the cart
// returns default items + cart link if there is
// returns default items if the cart is empty
if (sizeof(WC()->cart->get_cart()) != 0) {
$wrap = '<ul id="%1$s" class="%2$s">';
@galengidman
galengidman / README.md
Last active Jun 22, 2017
Quick-and-dirty plugin that allows you to specify custom search results for specific search queries.
View README.md

GG Custom Results

Quick-and-dirty plugin that allows you to specify custom search results for specific search queries.

Installation

Move gg-custom-results.php into either the /wp-content/plugins/ or /wp-content/mu-plugins/ directory. If you put it in plugins, you'll need to activate from Plugins menu in the WordPress admin. If you put in mu-plugins, it will be automatically active.

Configuration

You can define your custom search results in wp-config.php. Insert the following just above the line that reads /* That's all, stop editing! Happy blogging. */:

You can’t perform that action at this time.