Skip to content

Instantly share code, notes, and snippets.

View ericrasch's full-sized avatar

Eric Rasch ericrasch

View GitHub Profile
@ericrasch
ericrasch / is_child.php
Last active October 29, 2019 16:18
WordPress conditional function to check if a page is a parent/child/ancestor. In other words, if the page is within a tree of another page, show the code. Other code I've seen either only work with IDs, only check if it's a child, or detect all subpages (even outside of the direct tree).
/* =BEGIN: Check If Page Is Child
Source: http://bavotasan.com/2011/is_child-conditional-function-for-wordpress/
---------------------------------------------------------------------------------------------------- */
function is_child( $page_id_or_slug ) { // $page_id_or_slug = The ID of the page we're looking for pages underneath
global $post; // load details about this page
if ( !is_numeric( $page_id_or_slug ) ) { // Used this code to change a slug to an ID, but had to change is_int to is_numeric for it to work.
$page = get_page_by_path( $page_id_or_slug );
$page_id_or_slug = $page->ID;
}
@ericrasch
ericrasch / RegEx Snippets.md
Last active October 6, 2019 12:37
RegEx Snippets

RegEx Snippets


Extract URLs

Find all links

Works pretty well in capturing the full URL when using this in a search (like in Sublime Text 2). (https?|ftps?)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/?

@ericrasch
ericrasch / Steps to Winning Featured Snippets.md
Last active October 6, 2019 12:10
Steps to Winning Featured Snippets
@ericrasch
ericrasch / disable-xml-rpc.php
Created April 10, 2015 18:46
Disable XML-RPC + Pingback WordPress Plugin
<?php
/*
Plugin Name: Disable XML-RPC + Pingback
Plugin URI: http://www.philerb.com/wp-plugins/
Description: This plugin disables XML-RPC API + pingbacks in WordPress 3.5+, which is enabled by default. 2 WP plugins were combined together to cover all bases.
Version: 1.0.0
Author: Eric Rasch
Author URI: http://ericrasch.com
License: GPLv2
*/
@ericrasch
ericrasch / dabblet.css
Created March 15, 2012 16:41
Horizontal Type Line Behind Text
/**
* Horizontal Type Line Behind Text
* Inspired by this discussion @ CSS-Tricks: http://css-tricks.com/forums/discussion/comment/51357#Comment_51357
* Available on jsFiddle: http://jsfiddle.net/ericrasch/jAXXA/
* Available on Dabblet: http://dabblet.com/gist/2045198
* Available on GitHub Gist: https://gist.github.com/2045198
*/
h2 {
font: 33px sans-serif;
@ericrasch
ericrasch / jamstack-resources.md
Last active December 28, 2018 16:50
Resources for JAMstacking websites
@ericrasch
ericrasch / first-paragraph-class.php
Created March 29, 2012 21:26
WordPress: Add Class to first Paragraph in WordPress the_content; (add this to the functions.php in your Theme)
<?php
/* =BEGIN: Add Class to first Paragraph in WordPress the_content();
Source: http://webdevbits.com/wordpress/add-class-to-first-paragraph-in-wordpress-the_content/
---------------------------------------------------------------------------------------------------- */
function first_paragraph($content){
// Testing to see if the content is a Page or Custom Post Type of school, if so, display the text normally (without the class = intro).
if ( is_page() || ('school' == get_post_type() ) ) {
return preg_replace('/<p([^>]+)?>/', '<p$1>', $content, 1);
} else {
return preg_replace('/<p([^>]+)?>/', '<p$1 class="intro">', $content, 1);
@ericrasch
ericrasch / database encoding fix.sql
Last active July 17, 2018 07:48
Fix WordPress database encoding issues with these MySQL queries... source #1: http://tanyanam.com/technology/fixing-encoding-issues-on-wordpress-comments-display-as-question-marks source #2: http://stackoverflow.com/a/3568144/284091 The 3 groups of repeated queries include the post content, post title, and the post slug.
ALTER DATABASE 'my_wp_database' CHARACTER SET utf8;
ALTER TABLE 'wp_comments' CHARACTER SET utf8;
alter table 'wp_comments' change comment_content comment_content LONGTEXT CHARACTER SET utf8;
alter table 'wp_comments' change comment_author comment_author LONGTEXT CHARACTER SET utf8;
update `wp_posts` set `post_content` = replace(`post_content` ,'á','á');
update `wp_posts` set `post_content` = replace(`post_content` ,'é','é');
update `wp_posts` set `post_content` = replace(`post_content` ,'í©','é');
update `wp_posts` set `post_content` = replace(`post_content` ,'ó','ó');
@ericrasch
ericrasch / Increasing Website Traffic.md
Created August 4, 2016 19:55
Increasing Website Traffic Case Studies
@ericrasch
ericrasch / flatten-git-repo.md
Created May 8, 2018 17:25
Completely Flattening a Git Repository
$ cd {{project-directory}}
$ rm -rf .git
$ git init
$ git add .
$ git commit -m 'Initial commit'
$ git remote add origin {{url}}
$ git push --force