Skip to content

Instantly share code, notes, and snippets.

View hearvox's full-sized avatar

Barrett Golding hearvox

View GitHub Profile
@hearvox
hearvox / wp-admin-urls.md
Last active May 1, 2024 12:04
WordPress admin URLs.

Admin or login to a site:
/admin
For some webhosts, inc. Media Temple:
/wp-admin

All Settings list (wp_options database table):
/wp-admin/options.php

Jetpack modules settings (old admin page):
/wp-admin/admin.php?page=jetpack_modules

@hearvox
hearvox / wp_email_antispam_shortcode.php
Created February 24, 2018 20:12
WordPress: Shortcode to hide email address from Spam Bots
<?php
/**
* Shortcode to hide email address from Spam Bots.
*
* Example: [email]me@mysite.com[/email]
*
* @uses antispambot() Wordpress native function
*
* @param array $atts Shortcode attributes. Not used.
@hearvox
hearvox / wp-top-parent-body-class.php
Last active February 23, 2023 16:22
Add class name for top-level parent category or page to body tag in WordPress posts, pages, and archives.
<?php
/**
* Insert class into body tag for highest level Category or Page.
*
* Pages and Categories with identical slugs get the same class.
* Works on Pages, Posts, and Category achives.
*
* @return string $top_slug Class name for body tag.
*/
function top_cat_or_page_body_class( $class ) {
@hearvox
hearvox / g-form-sheet-email.js
Created October 29, 2022 15:12
Upon Google Form submission, send response values to respondent in an emailed PDF attachment
/**
* Process form data: make PDF, send email; trigged on Form Submit.
*
* Documentation:
* https://docs.google.com/document/d/1O4Y-3VqhhnL-kXPXM3S2XDoQebevIH7UoXQUxpjjtuo/edit
*
* @param {e} obj Form data (includes user-submitted field values).
*
* @return void
*/
@hearvox
hearvox / wp_2020_custom.php
Last active September 17, 2022 16:34
WordPress Twenty Twenty theme custimizations, via custom plugin (e.g., mod date in post meta)
<?php
/**
* Adds modified date to displayed post meta.
*
* Uses action in theme's /inc/template-tags.php file.
* Param values passed by the action hook.
* @param int $post_id The ID of the post.
* @param array $post_meta An array of post meta information.
* @param string $location The location where the meta is shown.
*/
@hearvox
hearvox / wordpress-notes.php
Last active April 13, 2022 15:36
WordPress notes, admin URLs,, etc.
<?php
/*
WordPress settings list (serialized data hidden):
/wp-admin/options.php
Jetpack settings by modules (defualt hidden):
/wp-admin/admin.php?page=jetpack_modules
List Reusable Blocks (CPT):
@hearvox
hearvox / wp-insert-attach-media.php
Last active October 19, 2021 08:29
WordPress script adds files to Media Library; attaches files to posts.
<?php
/**
* Add files to Media Library; attach files to posts.
*
* This is for adding files to Media Library already in /uploads/.
* If files are elsewhere, adapt script.
*
* Attempts to attach file to post:
* Searches thru post content for the filename.
* If a post is found, then uses post ID and publish-date
@hearvox
hearvox / get_string_between.php
Created January 11, 2019 20:30
Get a string between two specified strings (can parse XML, HTML, or other code/text).
<?php
// @ see: http://www.justin-cook.com/2006/03/31/php-parse-a-string-between-two-strings/
function get_string_between( $string, $start, $end){
$string = " " . $string; // Convert to string.
$ini = strpos( $string, $start ); // Position of start text.
if ($ini == 0) {
return "";
}
$ini += strlen( $start ); // Length of start text.
@hearvox
hearvox / wp-yoast-hooks.php
Last active March 6, 2021 13:02
Hooks to disable Yoast SEO plugin features and admin screen controls.
<?php
/*******************************
=Yoast SEO Hooks (includes Premium)
******************************/
/* Remove default redirects feature, for posts and term.
* @link https://kb.yoast.com/kb/how-to-disable-automatic-redirects/
*/
add_filter('wpseo_premium_post_redirect_slug_change', '__return_true' );
add_filter('wpseo_premium_term_redirect_slug_change', '__return_true' );
@hearvox
hearvox / wp-media-lib-size-col.php
Created November 26, 2018 18:26
Add image data to new column to Media Library: file-size (bytes), image dimensions (pixels), and optional ratio between the two.
<?php
/* Add image data column to Media Library */
/**
* Add columns (file-size) to the Media Library list table.
*
* @param array $posts_columns Existing array of columns displayed in the Media list table.
* @return array Amended array of columns to be displayed in the Media list table.
*/
function my_media_columns( $posts_columns ) {
$posts_columns['size'] = __( 'Size', 'headecon' );