Skip to content

Instantly share code, notes, and snippets.

View danemorgan's full-sized avatar

Dane Morgan danemorgan

View GitHub Profile
@danemorgan
danemorgan / theme-functions.php
Last active June 30, 2021 08:57
Sends /page/ paths with a negative category parameter to base uri
/**
* Sends /page/ paths with a negative category parameter to base uri
*/
function csm_no_negative_cat_list() {
if ( isset( $_GET['cat'] ) && $_GET['cat'] == -1 ) {
$uri = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"];
$parsed_uri = parse_url( $uri );
$parsed_path = preg_replace( "/\/page\/[0-9]+/", '', $parsed_uri['path'] );
@danemorgan
danemorgan / parent-theme-mod-fallback.php
Created June 20, 2021 22:38 — forked from justintadlock/parent-theme-mod-fallback.php
Get theme mods that fall back to the stored parent theme mod if child theme is active.
<?php
/**
* The purpose of this code is to show how you can use theme mods that will fall back to
* the already-set mods of the parent theme. So, when a child theme is active, the code
* checks, in the following order: 1) child theme mod, 2) parent theme mod, 3) default.
*/
function jt_get_theme_mod( $name, $default = false ) {
if ( is_child_theme() )
<?php
/**
* Get the attachment ID of an image from it's URL.
*
* @param string $image_url The URL for the image you need an id for.
*
* @return mixed
*/
function theme_get_image_id($image_url) {
public function get_author_archive_post_types() {
/**
* Filters the array of post types that are shown on an author's archive.
*
* @param array $args The post types that are shown on an author archive.
*/
return \apply_filters( 'wpseo_author_archive_post_types', [ 'post', 'custom_post_type' ] );
}
@danemorgan
danemorgan / acf-php-to-json.php
Last active September 30, 2019 19:19 — forked from ollietreend/acf-php-to-json.php
Convert Advanced Custom Fields Pro configuration from PHP to JSON.
<?php
/**
* Plugin Name: Convert ACF PHP to JSON
* Description: Convert Advanced Custom Fields Pro configuration from PHP to JSON.
*/
namespace ConvertAcfPhpToJson;
/**
* Add submenu item under 'Custom Fields'
@danemorgan
danemorgan / wp.jquery.default.js
Created July 2, 2019 20:48 — forked from bacoords/wp.jquery.default.js
Just a default wrapper
(function($) {
// Any generic functions can go here...
$(document).ready(function($){
// Anything that needs to wait for the document to be ready goes here
});
@danemorgan
danemorgan / remove-empty-anchor-spam.php
Last active January 7, 2018 07:19
Remove empty anchor #spam from #comments. #WordPress
<?php
/**
* Removes comment spam anchors with empty nodeValues.
*
* @param $comment_content
*
* @return string
*/
function dmm_remove_empty_anchors_in_comments( $comment_content ) {
// Grab the comment content.
@danemorgan
danemorgan / delete-dom-nodes.php
Created November 29, 2017 14:15
Have to loop backward through the DOMnodeList to delete nodes
$comment_anchors = $dom_comment->getElementsByTagName( 'a' );
for ( $i = $comment_anchors->length; --$i >=0; ) :
$comment_anchor = $comment_anchors->item( $i );
if ( trim ( $comment_anchor->nodeValue ) === '' ) :
$comment_anchor->parentNode->removeChild( $comment_anchor );
endif;
endfor;
@danemorgan
danemorgan / ampps-mysql-fix.md
Created October 14, 2017 14:15 — forked from irazasyed/ampps-mysql-fix.md
AMPPS MySQL not working, Solution!

AMPPS MySQL not working, Solution!

  1. Open Ampps Application -> MySQL Tab -> Configuration.

  2. In [mysqld] section, add the following line: innodb_force_recovery = 1

  3. Save the file and try starting MySQL

  4. Remove that line which you just added and Save.

@danemorgan
danemorgan / get-image-id.php
Created October 6, 2017 19:31
Get the WordPress attachment ID of an image from it's URL
/**
* Get the attachment ID of an image from it's URL.
*
* @link https://pippinsplugins.com/retrieve-attachment-id-from-image-url/
*
* @param $image_url
*
* @return mixed
*/
function dmgist_get_image_id($image_url) {