Skip to content

Instantly share code, notes, and snippets.

@jamesmthornton
jamesmthornton / functions.php
Created April 12, 2020 13:07
Output internal pingback/trackbacks on Genesis Wordpress sites
<?php
// remove whatever action your current ping method relies on, typically your comments template
remove_action( 'genesis_pings', 'genesis_do_pings' );
// you can use the comments_text filter hook if you don't have genesis
add_filter( 'genesis_pings', function( $ifca_pings ) {
if ( acme_post_has( 'pings', get_the_ID() ) ) {
echo'<div id="internal-links" class="comment-respond entry-pings">';
@jamesmthornton
jamesmthornton / git_disconnect_repo_from_remote
Created March 16, 2020 12:28
git disconnect local repository from remote origin
# make sure we're on development branch
git checkout development
# disconnect local files from remote origin, as in cases where source files are templates (e.g no fork)
git remote rm origin
# connect local files to intended remote origin we're pushing to
git add origin https://github.com/username/new-repo.git
# push changes
git push -u origin development
@jamesmthornton
jamesmthornton / search.php
Created January 25, 2020 22:07
Return Google Custom Search JSON API results with custom Genesis for Wordpress Search.php template
<?php
/**
* Author: Jim Thornton
* Return Google CSE search results
*
*/
add_action( 'genesis_after_header', 'genesis_do_search_title' );
function genesis_do_search_title() {
@jamesmthornton
jamesmthornton / do_related_posts.php
Created January 14, 2020 19:19
Simple function to output three related posts with Wordpress block classes if selected using ACF relationships field named "related_posts" (relies on a Genesis hook)
@jamesmthornton
jamesmthornton / functions.php
Created December 17, 2019 20:47
Remove "Home" link and trailing slash from breadcrumbs in Genesis themes
<?php
// Remove "Home" link and trailing slash from breadcrumbs in Genesis themes
add_filter( 'genesis_home_crumb', 'remove_home_breadcrumb' );
function remove_home_breadcrumb( $crumb ) {
$crumb = '';
}
@jamesmthornton
jamesmthornton / functions.php
Last active October 15, 2021 19:24
Add Google Tag Manager to Wordpress and Load Only If An Admin is NOT Logged In
<?php // do not copy this line and make sure to replace "XXXXXXX" with your tag manager ID
// add Google Tag Manager after opening body tag on wordpress (part 1)
add_action( 'wp_head', 'add_custom_google_tag_manager_1', 1 );
function add_custom_google_tag_manager_1() {
// if user is not a logged in admin then load gtm script tag
if( !current_user_can('administrator') ) {
@jamesmthornton
jamesmthornton / page-work.php
Created January 10, 2019 02:28
Get specific post from CPT relying on ACF flexible content and output to template
<?php
// Open the Work CPT Loop and grab our target post Work Blocks
$args = get_post( 845 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
@jamesmthornton
jamesmthornton / Override wp plugin function in functions.php
Last active September 28, 2018 23:43
Override fb events calendar plugin function to reposition plugin css to override it with theme css
<?php
remove_action('wp_head','tiva_facebook_events_calendar_frontend_assests');
// function from tiva fb events calendar plugin - edited relative file paths, repositioning css
function tiva_fbec_js_frontend_assests1() {
// JS Files
wp_enqueue_script('tiva-facebook-events-calendar-script', network_site_url() . '/wp-content/plugins/tiva-facebook-events-calendar/assets/js/calendar.js', array(), '');
}
function tiva_fbec_css_frontend_assests1() {
@jamesmthornton
jamesmthornton / hide-show-medium-style-nav.js
Created August 28, 2018 02:35
Determine scroll direction and trigger a function depending on whether user is scrolling up or down
var previousScroll = 0;
$(window).scroll(function(){
var currentScroll = $(this).scrollTop();
if ( currentScroll < $(document).height() - $(window).height() ){
// If we're scrolling down the page or at the top of the page
if ( currentScroll > previousScroll || previousScroll < 300 || currentScroll < 300){
// hide nav
<?php
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_560aae855e3b5',
'title' => 'Press',
'fields' => array(
array(
'key' => 'field_560aae8e3338a',