Skip to content

Instantly share code, notes, and snippets.

View gjhead's full-sized avatar
💭
huh?

G. Jason Head gjhead

💭
huh?
View GitHub Profile
<?php
add_filter( 'acf/fields/wysiwyg/toolbars', function ( $toolbars ) {
// Register a basic toolbar with a single row of options
$toolbars['Custom One'][1] = [ 'bold', 'italic', 'underline', 'forecolor', 'link', 'unlink' ];
// Register another toolbar, this time with two rows of options.
$toolbars['Custom Two'][1] = [ 'bold', 'italic', 'underline', 'strikethrough', 'forecolor', 'wp_adv' ];
$toolbars['Custom Two'][2] = [ 'bullist', 'numlist', 'alignleft', 'aligncenter', 'alignright' ];
You can use environment variables for site statuses though. First add a variable to your .env file or wherever else
environment variables are set – for example something like SITE_FOOBAR_STATUS=0 (it can be named anything). Then open the
site's settings page in the CP, and enter/select that variable with a $ prefix in the site's "Status" field.
That way, the environment variable reference will be saved to project config, and not the actual value, which means you can
set that variable to either 1 or 0 to enable or disable the site across different environments.
You can query for that parent page's entry model with a new ElementCriteriaModel.
{% set mainEntry = craft.entries.id(100).first() %}
{% if mainEntry %}
{% set matrixField = mainEntry.matrixFieldHandle %}
{% set firstContentBlock = matrixField.type('content').first() %}
{% if firstContentBlock %}
{{ firstContentBlock.myRichTextFieldHandle }}
@gjhead
gjhead / googleMap.twig
Created August 13, 2020 19:22
You obviously need to make sure your fields match up - but this will take an address and turn it into a link to a google map.
{{ entry.eventLocation.streetAddress1 }}<br>
{% if entry.eventLocation.streetAddress2 | length %}{{ entry.eventLocation.streetAddress2 }}<br>{% endif %}
{% if entry.eventLocation.city %}{{ entry.eventLocation.city }}, {% endif %}{% if entry.eventLocation.state %}{{ entry.eventLocation.state }}{% endif %}{% if entry.eventLocation.zipCode %} {{ entry.eventLocation.zipCode}}{% endif %}</p>
<a class="link" href="https://www.google.com/maps/search/?api=1&query={{ entry.eventLocation.streetAddress1|escape('url')}}{% if entry.eventLocation.city %}%20{{ entry.eventLocation.city|escape('url') }}{% endif %}{% if entry.eventLocation.state %}%20%2C{{ entry.eventLocation.state|escape('url') }}{% endif %}{% if entry.eventLocation.zipCode %}%20{{ entry.eventLocation.zipCode|escape('url') }}{% endif %}" rel="nofollow" target="_blank">Get Directions</a>
{% if craft.request.isAjax %}
{% set layout = "_ajaxLayout" %}
{% else %}
{% set layout = "_layout" %}
{% endif %}
{% extends layout %}
{% set limit = 10 %}
{% set params = { section: 'news', limit: limit} %}
button {
display: inline-block;
border: none;
margin: 0;
padding: 0;
font-family: sans-serif; /* Use whatever font-family you want */
font-size: 1rem;
line-height: 1;
background: transparent;
-webkit-appearance: none;
@gjhead
gjhead / gist:87a71c6502f65b4568a586e39336993f
Last active June 26, 2020 15:19
Restablish .gitignore
For when you make a change to .gitignore and the stupid thing still keeps old files in there.
To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename
To untrack every file that is now in your .gitignore:
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
@gjhead
gjhead / gist:e5b03ab902bec22efb6c728de0de3428
Last active March 10, 2020 14:11
craft cms - can't do max-width for transforms so you need to check it before the transform.
{% if asset.width > asset.getWidth('detail') %}
{% do asset.setTransform('detail') %}
{% endif %}
<img src="{{ asset.url }}" alt="{{ asset.title }}">
<p>Event Date: {{ entry.eventDate }}</p>
<p>Event Start : {{ entry.eventStartTime }}</p>
<p>Event End : {{ entry.eventEndTime }}</p>
<p>datetime: {{ entry.eventDate | date("Y-m-d")}}T{% if entry.eventStartTime|length %}{{ entry.eventStartTime | date("Hi") }}{% endif %}
<div class="form-text">
<label for="first-name" class="vh">First Name</label>
<input type="text" name="first-name" id="first-name" placeholder="First Name">
</div>
<div class="form-text">
<label for="last-name" class="vh">Last Name</label>
<input type="text" name="last-name" id="last-name" placeholder="Last Name">
</div>