Skip to content

Instantly share code, notes, and snippets.

@ammist
ammist / find-copy-change
Last active January 1, 2016 15:18
find files newer than [filename] and copy them to [dirname]
find . -type f -newer '[filename]' -print0 | xargs -0 -I {} cp {} [dirname]
# replace strings in a file without creating a backup. the -i parameter would create a backup if you so desired
sed -i '' 's/techliminal/localhost/g' [filename]
# find all the javascript files and list them
find . -name *.js -print | xargs ls -l
# change the owner of all the javascript files
# Looks like the sudo has to be on the xargs / chown part of the operation
@ammist
ammist / genesis_comments_functions.php
Created July 27, 2013 22:38
Genesis Comment Hacking - change the time and date. You can put this in your functions.php file. If you do this, your comments will show a relative date (e.g. posted 10 days ago). The original genesis code is in the /genesis/lib/structure/comments.php file.
function my_comment_listing($comment, $args, $depth){
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
<?php do_action( 'genesis_before_comment' ); ?>
<div class="comment-header">
<div class="comment-author vcard">
@ammist
ammist / tl-events.php
Created July 5, 2013 23:44
This is a simple way to add event meta field on WordPress posts. You could use this for a custom post type, but this is some code I wrote in 2010 to extend Thesis with event information. It doesn't support recurring events, or a calendar view, but it's pretty darn handy for something really simple.
<?php
/**
* TL EVENTS
*
* Functionality for adding time, date for events, displaying them by week, etc.
* This assumes your events are posts in the "Events" category, but could easily be
* extended to other stuff.
*/
<!-- replace the below with this -->
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php if (is_category(1)){ ?>
<img src="http://asdfha.jpg" class="header-image" width="" height="" alt="Header 5" />
<?php } else {
$header_image = get_header_image(); ?>
<img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
<?php } ?>
</a>
@ammist
ammist / genesis_event_calendar_page.php
Created June 6, 2013 01:54
If you are using the Events Calendar PRO with Community events submission with Genesis, you may run into an issue where the submission form is replicated in other widget areas where you are including posts or pages with content. This updated template file can be used to avoid this problem. Just save this code as page.php in your child theme. Thi…
<?php
/* When we're using the event calendar community feature, we need to disable any
widget areas that might be displaying extra copies of the form. In theory Modern
Tribe will fix this in a future release, but, in the meantime... */
function check_for_event_calendar_pro_router_page(){
global $wp_query;
@ammist
ammist / google_maps_sample.html
Created March 1, 2013 20:24
Google Map with Two Markers
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Google Maps JavaScript API v3 Example: Marker Simple</title>
<link href="https://developers.google.com/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
function initialize() {
@ammist
ammist / attach_category.php
Last active October 11, 2015 22:58
WordPress: Attach a category of posts to a page or other post
/* if using this with Genesis, hook this after the loop.
The name of the custom field can be hidden, if you provide a metabox for choosing it.
The simplest thing is to leave it visible and just use the custom field selector.
*/
function tl_attach_category(){
global $post;
$attach_option = get_post_meta($post->ID, 'attach_category', true);
// You might want to do different things for different categories
@ammist
ammist / wp-common-queries.sql
Created December 22, 2011 00:57
WordPress SQL queries I use a lot
-- Life is better when you can cut and paste
-- Post meta
-------------
-- Site Options
-------------
select distinct option_name from wp_options;
@ammist
ammist / gist:1252863
Created September 30, 2011 06:22
[WP] Install WP quickly
# This script is for shell users who have previously created a database.
mkdir ~/installs
cd ~/installs
wget http://wordpress.org/latest.zip
unzip latest.zip
cp wordpress/* ~/public_html/
cd ~/public_html/
cp wp-config-sample.php wp-config.php
vi wp-config.php
@ammist
ammist / change_urls.sql
Created August 31, 2011 07:28
MySQL Wrangling
-- handy for moving a database from prouction to your local environment.
-- change URL's in wordpress single-site install. Replace with your own URL's.
-- this doesn't address serialized options.
UPDATE wp_options SET option_value = "http://localhost:8888" WHERE option_name = "home";
UPDATE wp_options SET option_value = "http://localhost:8888" WHERE option_name = "siteurl";
update wp_postmeta set meta_value = replace(meta_value, 'http://example.com', 'http://localhost:8888') where meta_key='_menu_item_url';
update wp_posts set post_content = replace(post_content, 'http://example.com', 'http://localhost:8888');