Skip to content

Instantly share code, notes, and snippets.

View tomfinitely's full-sized avatar

Tom Finley tomfinitely

View GitHub Profile
@coulterpeterson
coulterpeterson / readme.md
Last active October 2, 2024 18:30
How To Import a Bedrock WordPress Project Into LocalWP

How To Import a Bedrock WordPress Project Into LocalWP

  1. Per the official doc from Bedrock, start by creating a new site in Local.
  2. Use the "open site folder" or "open site shell" option, delete the public folder in \Local Sites\YOURSITE\app\
  3. While in \Local Sites\YOURSITE\app, clone your project down into this folder.
  4. Open the .env file in app\YOURREPO\src and ensure:
    • DB_NAME=local
    • DB_USER=root
    • DB_PASSWORD=root
  • WP_HOME='https://YOURSITE.local'
@Clorith
Clorith / disable-fullscreen-snippet.php
Last active November 25, 2024 15:10
Quick drop-in snippet to disable the default full-screen editing mode and welcome guide in WordPress when a user first visits the edit interface.
<?php
function wp378934573289_js_head_print() {
$screen = get_current_screen();
// Only add script in editor views.
if ( 'edit' !== $screen->parent_base ) {
return;
}
?>
@kingkool68
kingkool68 / maybe-sideload.php
Created November 21, 2020 04:19
Two WordPress functions for maybe side loading URLs to the media library. Useful for content migrations that need to be run multiple times without producing duplicate downloads.
<?php
/**
* Example useage:
*
* maybe_sideload_image( 'https://dummyimage.com/600x400/000/fff.png' ); // Downloads image to the media library and returns an attachment ID
* maybe_sideload_image( 'https://dummyimage.com/600x400/000/fff.png' ); // Returns an attachment ID as the image has already been downloaded and added to the media library
*/
/**
@kingkool68
kingkool68 / use-remote-media.php
Last active March 24, 2024 11:37
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( 'RH_USE_REMOTE_MEDIA_URL', 'https://example.com/' );
// Put the rest of this in functions.php or a custom plugin or somewhere else.
if ( defined( 'RH_USE_REMOTE_MEDIA_URL' ) && ! empty( RH_USE_REMOTE_MEDIA_URL ) ) {
add_filter( 'wp_get_attachment_image_src', 'filter_wp_get_attachment_image_src' );
add_filter( 'wp_calculate_image_srcset', 'filter_wp_calculate_image_srcset' );
add_filter( 'wp_get_attachment_url', 'filter_wp_get_attachment_url' );
}
// create a bookmark and use this code as the URL, you can now toggle the css on/off
// thanks+credit: https://dev.to/gajus/my-favorite-css-hack-32g3
javascript: (function() {
var elements = document.body.getElementsByTagName('*');
var items = [];
for (var i = 0; i < elements.length; i++) {
if (elements[i].innerHTML.indexOf('* { background:#000!important;color:#0f0!important;outline:solid #f00 1px!important; background-color: rgba(255,0,0,.2) !important; }') != -1) {
items.push(elements[i]);
}
}
@jom
jom / functions.php
Last active December 30, 2020 20:56
Remove Resume Preview Step
<?php
/**
* Remove the preview step when submitting resumes. Code goes in theme functions.php or custom plugin.
* @param array $steps
* @return array
*/
add_filter( 'submit_resume_steps', function( $steps ) {
@wpfangirl
wpfangirl / portfolio-block-template.php
Last active March 28, 2020 19:42
Add Gutenberg suport and a block template to an existing portfolio post type (e.g. from the Portfolio Post Type or Genesis Portfolio Pro plugin)
<?php
/**
* Adds block template to existing post type 'portfolio' with taxonomies 'portfolio_category' and 'portfolio_tag'.
*/
// Add Block Template to existing portfolio post type
function bbp_add_portfolio_template() {
$post_type_object = get_post_type_object( 'portfolio' );
$post_type_object->show_in_rest = true;
$post_type_object->rest_base = 'portfolio';
@jsn789
jsn789 / add-gtm-wp.php
Last active September 4, 2024 13:38
Add Google Tag Manager through functions.php in WordPress
/* Add Google Tag Manager javascript code as close to
the opening <head> tag as possible
=====================================================*/
function add_gtm_head(){
?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
@skyshab
skyshab / example.php
Last active March 2, 2024 18:41
Adding additional emails to RSVP confirmations
<?php
/**
* BCC custom email on all Event Tickets' RSVP ticket emails
*/
add_filter( 'tribe_rsvp_email_headers', 'my_add_bcc_email_headers' );
function my_add_bcc_email_headers() {
// set Headers to Event Tickets' default
$headers = array( 'Content-type: text/html' );
@topleague
topleague / css-grid-responsive-grid.css
Last active December 3, 2019 07:11
CSS Grid for Responsive Grid Layout in Genesis
/* CSS Grid for Responsive Grid Layout | Credit: Sridhar Katakam */
.content-archive .content {
float: none;
}
.articles {
display: -webkit-box;
display: -ms-flexbox;
display: flex;