Skip to content

Instantly share code, notes, and snippets.

<?php
function gg_asset_url( $path = '' ) {
return esc_url( get_template_directory_uri() . '/assets/' . $path );
}
function gg_asset_path( $path = '' ) {
return get_template_directory() . '/assets/' . $path;
}
@galengidman
galengidman / README.md
Last active June 22, 2017 17:50
Quick-and-dirty plugin that allows you to specify custom search results for specific search queries.

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. */:

@galengidman
galengidman / functions.php
Last active July 17, 2017 07:36
Check if WooCommerce cart has items, add link to have if it does
<?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 / youtube-id-from-url.php
Created January 23, 2017 22:31
Get a YouTube video ID from any format of YouTube URL.
<?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 );
#!/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 / user.php
Last active September 23, 2020 19:23
Example WordPress user model
<?php
class User {
public $ID;
public $_user;
public $attributes = [
'description',
@galengidman
galengidman / index.html
Last active November 26, 2020 17:36
`display: table` sticky footer trick
<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 / functions.php
Last active June 6, 2021 12:10
Adding Static Menu Items to wp_nav_menu()
<?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 / merge-wp-query-args.php
Created September 21, 2021 21:51
Merge WP_Query args, recursively for meta_query and tax_query
<?php
function merge_wp_query_args(...$sets)
{
$meta_query = [];
$tax_query = [];
foreach ($sets as &$set) {
if (array_key_exists('meta_query', $set)) {
$meta_query[] = $set['meta_query'];
@galengidman
galengidman / search.php
Last active September 26, 2021 16:45
WordPress search form & results for custom post type
<?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' ) ) {