Skip to content

Instantly share code, notes, and snippets.

View johnmccole's full-sized avatar
💭
I may be slow to respond.

John McCole johnmccole

💭
I may be slow to respond.
  • Glasgow, Scotland
View GitHub Profile
@johnmccole
johnmccole / http.conf
Last active December 12, 2017 17:22
Add either of the following to the domain's .htaccess file.
<IfModule mod_rewrite.c>
# BEGIN Force https to http
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteRule ^(.*) http://%{HTTP_HOST}/$1 [R=301,L]
# END Force https to http
</IfModule>
@johnmccole
johnmccole / siblings.php
Last active December 12, 2017 17:39
Copy to you themes template, update the name of the CPT as required.
<?php
global $post;
if ( isset ($post) ){
$post_parent = $post->ID;
if ( !empty($post->post_parent) ){
$post_parent = $post->post_parent;
}
$args = array( 'posts_per_page' => -1, 'post_parent' => $post->post_parent, 'post_type'=> 'custom-post-name' );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
@johnmccole
johnmccole / footer-shop.php
Last active January 4, 2018 09:13
Installing WooCommere to a site using the Sage theme causes shop pages to have duplicate content. To resolve this, create several new files, header-shop.php, footer-shop.php and sidebar-shop.php. This will remove both instances of the element. You can then edit files with custom content to add required elements (e.g titles, breadcrumbs). Example…
@johnmccole
johnmccole / headers.sass
Last active October 5, 2021 10:56
Target all header tags with a for loop in SASS
@for $index from 1 through 6 {
h#{$index} {
// style code
}
}
@johnmccole
johnmccole / clean.js
Created January 12, 2018 12:09
Add clean.js to remove all useless nodes from the document.
function clean(node)
{
for(var n = 0; n < node.childNodes.length; n ++)
{
var child = node.childNodes[n];
if
(
child.nodeType === 8 || (child.nodeType === 3 && !/\S/.test(child.nodeValue))
)
{
@johnmccole
johnmccole / pagination.blade.php
Last active June 22, 2022 15:59
Add pagination.php to the bottom of index.php to include custom links. Remember to remove/comment out the existing pagination. Edit the arguements in the array to customise the output.
@php global $wp_query @endphp
@if ($wp_query->max_num_pages > 1)
<nav class="post-nav">
<div class="pager">
@php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
@johnmccole
johnmccole / auto-complete-orders.php
Created January 22, 2018 14:36
Add auto-complete.php to the theme's functions.php to auto complete all orders.
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
$order->update_status( 'processing' );
}
@johnmccole
johnmccole / fallback-img.js
Last active January 30, 2018 10:51
Put an onerror event on images to load a fallback image if the original can't be found. Below is an example featured image.
<img src="<?php echo get_the_post_thumbnail_url(); ?>" alt="" onerror="this.onerror=null;this.src='<?= get_template_directory_uri(); ?>/dist/images/example.jpg';">
@johnmccole
johnmccole / reset_query.php
Created February 1, 2018 16:10
When outputting content fields to a template, the field must be within a page or post loop. If a custom loop is added to a page, this loop must then end with wp_reset_query to continue the output of the custom fields/page content.
// loop code
<?php wp_reset_query(); ?>
@johnmccole
johnmccole / functions.php
Last active September 13, 2023 12:05
Add the below snippet to functions.php to add the lost password url back into the login form when using wp_login_form(); Wrap the output text in html, it will be a text node without.
// Add lost password link to login form
add_action( 'login_form_middle', 'add_lost_password_link' );
function add_lost_password_link() {
return '<p class="forgot-password">Forgot Password? <a href="/wp-login.php?action=lostpassword">Click Here</a></p>';
}