Skip to content

Instantly share code, notes, and snippets.

View thetwopct's full-sized avatar

James Hunt thetwopct

View GitHub Profile
@thetwopct
thetwopct / single.php
Created June 15, 2019 06:36
List categories of a single post (run inside loop)
$taxonomy = 'category';
// Get the term IDs assigned to post.
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
// Separator between links.
$separator = ', ';
if ( ! empty( $post_terms ) && ! is_wp_error( $post_terms ) ) {
@thetwopct
thetwopct / home.php
Created June 15, 2019 07:09
List all blog categories (with permalinks)
<?php
echo '<div class="post-categories">';
$tax = 'category';
$terms = get_the_terms($post->ID, $tax);
if (!empty($terms)) :
if (count($terms) === 1) {
echo "<p>Category:</p>";
} else {
@thetwopct
thetwopct / single.php
Created June 15, 2019 07:48
Display all tags for a post with permalinks
<?php
$tags = get_tags();
if ($tags) {
echo '<ul class="tags">';
foreach ($tags as $tag) {
echo '<li>
<a href="' . get_tag_link( $tag->term_id ) . '"
title="' . sprintf( "View posts tagged with %s", $tag->name) . '">' . $tag->name .'</a>
</li>';
}
@thetwopct
thetwopct / settings.json
Last active June 16, 2019 07:06
VS Code Settings (WIP)
{
"html.format.enable": true,
//
// editor
//
"files.trimTrailingWhitespace": true,
"editor.cursorStyle": "line",
"editor.cursorWidth": 1,
"editor.wordWrap": "on",
"editor.wordWrapColumn": 90,
@thetwopct
thetwopct / image-handling-wordpress.php
Last active March 27, 2023 13:04
WordPress image handling (ACF / Background Images / Inline / srcset /
//
<?php
if ( has_post_thumbnail() ) {
echo wp_get_attachment_image(get_post_thumbnail_id($post->ID), '', false, array('class' => 'featured-image'));
} else {
echo '<img src="' . get_bloginfo( 'stylesheet_directory' )
. '/library/images/thumbnail-default.jpg" alt="default thumb" class="featured-image"/>';
}
?>
@thetwopct
thetwopct / entry-content.php
Last active June 21, 2019 07:52
Basic content to paste in to WordPress post or page for styling
<h2>Lorem Ipsum</h2>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula get dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate get, arcu. In enim justo, rhoncus ut imperdiet a.
https://www.youtube.com/watch?v=XOY3ZUO6P0k
<strong>Bold text</strong>
<em>Italic</em>
@thetwopct
thetwopct / gulpfile.js
Created June 22, 2019 16:06
Gulpfile for WordPress (3.9.1)
/**
* Configuration.
*
* You should only need to change these few values to get everything up and running
*/
var project = 'basetheme'; // Project Name - Lowercase, no spaces, used below in urls (use name of theme folder)
var projectURL = 'http://basetheme.dev'; // Project URL. Taken from your MAMP, WAMP or whatever local server you use.
/**
* File and folder links
@thetwopct
thetwopct / gulpfile.js
Last active June 24, 2019 09:19
Gulp File for WordPress (Gulp 4+)
/**
* Configuration.
*
* You should only need to change these few values to get everything up and running
*/
// Project Name - Lowercase, no spaces, used below in urls (use name of theme folder)
var project = 'basetheme';
// Local project URL. From MAMP or whatever local server you use.
var projectURL = 'http://basetheme.test';
@thetwopct
thetwopct / query.sql
Created July 5, 2019 03:56
Checking autoloaded data in WordPress MySQL
# Run this in SQL query of PHPmyAdmin
# Show the size of all the autoloaded data - this is loaded on *every* page of your site
SELECT SUM(LENGTH(option_value)) as autoload_size FROM wp_options WHERE autoload='yes';
# Show what is loading in autoload
SELECT LENGTH(option_value),option_name FROM wp_options WHERE autoload='yes' ORDER BY length(option_value) DESC LIMIT 20;
@thetwopct
thetwopct / bash.sh
Last active August 22, 2021 08:36
Create a ZIP file with password on command line
# zip a whole folder
zip -r [archive] [folder]
# example of zip a whole folder
zip -r plugins.zip plugins
# zip a whole folder with password
zip -er [archive] [folder]
# example zip a whole folder with password