Skip to content

Instantly share code, notes, and snippets.

Working from home

William Patton pattonwebz

Working from home
View GitHub Profile
pattonwebz / functions.php
Created Apr 12, 2018
Halt theme activation if attempting to activate on unsupported older php versions.
View functions.php
* Define the min version you support. Here I use 5.6 as example but change it to match your support version.
define( 'PREFIX_MIN_PHP_VERSION', '5.6' );
* Attach a function to check php version on the `after_theme_switch` hook.
add_action( 'after_switch_theme', 'prefix_test_for_min_php' );
pattonwebz / bs3-version.php
Created Feb 10, 2018
Code for bootstrap 3 responsive navbars in wordpress using wp-bootstrap-navwalker class
View bs3-version.php
* The register_nav_menus call should go inside your themes setup function
* (usually found inside functions.php).
'footer_nav' => __( 'Footer Menu', 'mytheme' ), // example of adding a menu location
'top_menu' => __( 'Top Menu', 'mytheme' ), // we will be using this top_menu location
pattonwebz / open-authors-reports.js
Created Dec 15, 2017
check child theme authors aren't uploading too frequently - opens submission reports of all authors currently in the queue viewed
View open-authors-reports.js
function openInNewTab(url) {
var win = window;, '_blank');
function get_authors() {
var authors = [];
jQuery('td.reporter').each( function() {
authors.push( jQuery( this ).text().trim() );
pattonwebz /
Last active Nov 12, 2017
called with: sh {url to theme zip file}.
# clear databse
wp db reset --yes
# Install WP with long title
wp core install --url=http://theme-review.loc --title="This is a really long long title to check if this theme design doesn't break with the long site title" --admin_user=admin --admin_password=admin
# Update wp.
wp core update
pattonwebz / pwwp_debug_logger.php
Created Oct 9, 2017
Function to handle some basic php logging with some logic for handling wp_error and any object/arrays.
View pwwp_debug_logger.php
* Puts messages into the error log
* Using php error_log put messages into the log depending on what kind of
* variable they are.
* @author William Patton -
* @param mixed $error this is the error we'll be outputting. Type is ambiguous.
pattonwebz / filter-opengraph-image-per-posttype.php
Last active Oct 9, 2017
How to use the filter in yoast seo to redefine a default image for only certain CPT that is used in the open graph tags.
View filter-opengraph-image-per-posttype.php
* Filters the image used in social meta tags added by yoast seo plugin.
* This is used to set a default social share image for various post types.
* @param string $image string containing link to image that is used in tags.
* @return string string containing maybe updated url to image
function pwwp_filter_yoast_opengraph_image( $image = '' ) {
pattonwebz / add-text-when-on-dev-or-staging.php
Last active Oct 9, 2017
Add a small banner of text to the header for dev/staging servers.
View add-text-when-on-dev-or-staging.php
* Adds a small banner of text when on specific domains.
* @return string of html or empty string
function pwwp_output_text_on_dev_or_staging_server() {
$output = '';
if ($_SERVER['SERVER_NAME'] === "") {
pattonwebz / repointImgs.js
Last active Feb 20, 2018
Update the src of images in the uploads directory of a site to point from a dev/staging domain to the live site. This prevents the need to move all of the images from a live site to a they images are unnecessary for the changes (but still nice to see them in some situations like when screenshots are being sent to the client).
View repointImgs.js
// this is the pattern we match against
var regexPattern = "/wp-content/uploads/";
// turn the pattern into a regular expression
var regExp = new RegExp(regexPattern);
// get an array of the images
var images=document.querySelectorAll('img');
// loop through each array item
// test if the src matches the pattern of containing '/wp-content/uploads/'
You can’t perform that action at this time.