Skip to content

Instantly share code, notes, and snippets.

View dcooney's full-sized avatar

Darren Cooney dcooney

View GitHub Profile
@bradtraversy
bradtraversy / tailwind-webpack-setup.md
Last active May 3, 2024 07:35
Setup Webpack with Tailwind CSS

Webpack & Tailwind CSS Setup

Create your package.json

npm init -y

Create your src folder

Create a folder called src and add an empty index.js file. The code that webpack compiles goes in here including any Javascript modules and the main Tailwind file.

@jenssogaard
jenssogaard / ACF Gutenberg get block fields
Created February 22, 2019 21:08
Helper class for ACF and Gutenberg. Get blocks fields by passing block_id and post_id.
<?php
namespace JensSogaard;
class BlockHelper
{
/**
* Gets ACF fields for a specific block on a given post
* @author Jens Soegaard <jens@jenssogaard.com>
*/
public function getBlockFromPage(string $block_id, int $post_id)
@bfintal
bfintal / cheatsheet.js
Last active April 11, 2024 00:22
Gutenberg Cheat Sheet
// Get the data of a block
wp.data.select( 'core/block-editor' ).getBlocks()[0]
// Update attributes of another block
// wp.data.dispatch( 'core/editor' ).updateBlockAttributes( clientID, attributes )
wp.data.dispatch( 'core/block-editor' ).updateBlockAttributes( '10d88a6d-95d6-4e07-8293-5f59c83a26c0', { heading: 'New Heading' } )
// Get currently selected block.
wp.data.select( 'core/block-editor' ).getBlockSelectionStart()
@chranderson
chranderson / nvmCommands.js
Last active May 3, 2024 07:06
Useful NVM commands
// check version
node -v || node --version
// list locally installed versions of node
nvm ls
// list remove available versions of node
nvm ls-remote
// install specific version of node
@dcooney
dcooney / tmpl-alm-template.js
Last active March 8, 2017 21:17
Example Underscore.js repeater template for the REST API + Ajax Load More
<script type="text/html" id="tmpl-alm-template">
<li <# if(!data.thumbnail){ #> class="no-img" <# } #>>
<# if(data.thumbnail){ #>
<a href="{{{data.link}}}"><img src="{{{data.thumbnail}}}" alt="{{{data.thumbnail_alt}}}" /></a>
<# } #>
<h3><a href="{{{data.link}}}">{{{ data.post_title }}}</a></h1></h3>
<p class="entry-meta">{{{ data.date }}}</p>
<p>{{{ data.post_excerpt }}}</p>
</li>
</script>
@danielbachhuber
danielbachhuber / collection-filter.js
Last active April 18, 2023 20:30
Add a custom taxonomy dropdown filter to the WordPress Media Library
(function(){
/**
* Create a new MediaLibraryTaxonomyFilter we later will instantiate
*/
var MediaLibraryTaxonomyFilter = wp.media.view.AttachmentFilters.extend({
id: 'media-attachment-taxonomy-filter',
createFilters: function() {
var filters = {};
// Formats the 'terms' we've included via wp_localize_script()
@sectsect
sectsect / get_the_terms_orderby_termorder.php
Last active December 9, 2016 17:34
"get_the_terms" to the order of the "term_order". (order by ASC.)
<?php
/*==================================================
"get_the_terms" to the order of the "term_order". (order by ASC.)
================================================== */
function get_the_terms_orderby_termorder($taxonomy){
global $post;
$terms = get_the_terms($post->ID, $taxonomy);
$array = array();
foreach($terms as $term){
$array[$term->term_order] = (object)array(
@alexpchin
alexpchin / Add_Existing_Project_To_Git.md
Created June 1, 2014 20:14
Add Existing Project To Git Repo

#Adding an existing project to GitHub using the command line

Simple steps to add existing project to Github.

1. Create a new repository on GitHub.

In Terminal, change the current working directory to your local project.

##2. Initialize the local directory as a Git repository.

git init
@dcooney
dcooney / gist:7793397
Created December 4, 2013 19:00
Get related posts by tag in WordPress
<?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
$tag_in = array();
foreach($tags as $tag):
setup_postdata($tag);
$tag_in[] = $tag->slug;
endforeach;
$the_tags = implode(",", $tag_in); //Create
@HoundstoothSTL
HoundstoothSTL / anchor-scroll-with-offset.js
Created May 3, 2013 15:43
Anchor scroll with fixed header offset
(function($) {
$('a[href*=#]:not([href=#])').click(function()
{
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
|| location.hostname == this.hostname)
{
var target = $(this.hash),
headerHeight = $(".primary-header").height() + 5; // Get fixed header height