Skip to content

Instantly share code, notes, and snippets.

@bacoords
bacoords / readme.md
Created November 29, 2022 15:21
Default WordPress Readme File

Project Name

This is the public folder for Project Name. It can be used for your local development and is also used to push code to the staging and live environments via WP Engine's Git Push.

It currently contains the source code for:

@bacoords
bacoords / .gitignore
Last active January 20, 2023 05:25
Default WordPress/WP Engine .gitignore File
# Wordpress - ignore core, configuration, examples, uploads and logs.
# Forked from: https://github.com/github/gitignore/blob/main/WordPress.gitignore
# Core
/wp-admin/
/wp-content/index.php
/wp-content/languages
/wp-content/plugins/index.php
/wp-content/themes/index.php
/wp-content/uploads/
@bacoords
bacoords / wc_mail.php
Created August 26, 2022 22:18
Since wc_mail doesn't seem to work perfectly, a custom version
<?php
/**
* Our custom alternative to wc_mail.
*
* @param mixed $to Receiver.
* @param mixed $subject Subject.
* @param mixed $message Message.
* @param string $headers Headers. (default: "Content-Type: text/html\r\n").
* @param string $attachments Attachments. (default: "").
* @return bool
@bacoords
bacoords / use-remote-media.php
Last active July 21, 2023 17:21 — forked from kingkool68/use-remote-media.php
Check if a local file exists in the WordPress media library and if it doesn't exist, replace the URL with a different URL. Helpful when working with a local site that doesn't have all of the media downloaded as the production site. See https://localwp.com/community/t/proxying-requests-to-wp-content-uploads-to-a-production-site/15701
<?php
// Put this in wp-config.php and replace https://example.com/ with the URL of the production site.
define( 'BC_USE_REMOTE_MEDIA_URL', 'https://example.com' );
// Put the rest of this in functions.php or a custom plugin or somewhere else.
if ( defined( 'BC_USE_REMOTE_MEDIA_URL' ) && ! empty( BC_USE_REMOTE_MEDIA_URL ) ) {
add_filter( 'wp_get_attachment_image_src', 'bc_filter_wp_get_attachment_image_src' );
add_filter( 'wp_calculate_image_srcset', 'bc_filter_wp_calculate_image_srcset' );
add_filter( 'wp_get_attachment_url', 'bc_filter_wp_get_attachment_url' );
}
@bacoords
bacoords / jquery-wrapper.js
Last active February 14, 2022 17:44
My default wrapper when using jQuery in WordPress
(function($) {
$(document).ready(function($){
});
})( jQuery );
@bacoords
bacoords / snippet.json
Created February 14, 2022 17:39
VSCode snippet for a simple jQuery wrapper
{
"JQuery Frame": {
"prefix": "wpjquery",
"body": [
"(function($) {",
"",
"\t$(document).ready(function($){",
"",
"\t\t$1",
"",
@bacoords
bacoords / understrap-post-nav.php
Created January 19, 2022 00:29
Replace Understrap post nav font-awesome reference with inline Bootstrap Icons SVGs
<?php
/**
* Display navigation to next/previous post when applicable.
*/
function understrap_post_nav() {
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous ) {
return;
@bacoords
bacoords / content-card.php
Created January 15, 2022 20:27
Understrap post content with card classes
<?php
/**
* Post rendering content according to caller of get_template_part
*
* @package Understrap
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
?>
@bacoords
bacoords / archive.php
Created January 15, 2022 20:26
Understrap archive with columns layout
<?php
/**
* The template for displaying archive pages
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package Understrap
*/
// Exit if accessed directly.
@bacoords
bacoords / custom-javascript.js
Created January 11, 2022 21:03
Understrap - how to use bootstrap components
// Add your custom JS here.
import Popover from 'bootstrap/js/dist/popover'
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
return new Popover(popoverTriggerEl)