Skip to content

Instantly share code, notes, and snippets.

View petenelson's full-sized avatar

Pete Nelson petenelson

View GitHub Profile
@petenelson
petenelson / gga-twitter-card.php
Created June 22, 2013 23:08
WordPress: Twitter Card
<?php
/*
Plugin Name: GGA Twitter Card
Description: Adds Twitter card meta tags to the header
Author: @GunGeekATX
*/
add_action('wp_head', 'gga_twitter_card_wp_head');
function gga_twitter_card_wp_head() {
@petenelson
petenelson / add-to-header.php
Created May 9, 2013 19:23
WordPress: Add custom CSS file to a post/page
// add to header.php prior to wp_head()
$custom_css_file = get_post_meta( get_the_id(), $key = 'custom-css-file', $single = true );
if (false !== $custom_css_file && !empty($custom_css_file))
wp_enqueue_style( get_the_id() . '-custom-css-file', get_template_directory_uri() . '/' . $custom_css_file, array(), $version_tag_here );
@petenelson
petenelson / custom-post-type-title-placeholder.php
Created May 2, 2013 14:51
WordPress - Change custom post type "Enter Title Here" placeholder
// via http://www.paulund.co.uk/change-the-enter-title-text-for-custom-post-types
// just saving it here for later reference
function change_default_title( $title ){
$screen = get_current_screen();
if ( $screen->post_type == 'product' ) {
return 'Enter New Product Here';
}
}
add_filter( 'enter_title_here', 'change_default_title' );
@petenelson
petenelson / chart-image.php
Created April 24, 2013 21:17
PHP - generate a date range progress bar chart as an image
<?php
// some defaults
$start = new DateTime('2013-04-11');
$end = new DateTime('2013-05-09');
$current = new DateTime('2013-04-19');
if (isset($_REQUEST['s']))
$start = new DateTime($_REQUEST['s']);
@petenelson
petenelson / page-api.php
Created February 6, 2013 19:14
WordPress: Create a REST API endpoint
<?php
/*
* Sample code for using WordPress as a REST API endpoint (vs AJAX Admin)
* Author: Pete Nelson @GunGeekATX
*
* 1) Create a page called API in WordPres
* 2) Create a file called page-api.php in your theme directory
* 3) Add code as-needed
*
*/
@petenelson
petenelson / gga-marketing-request.php
Last active March 25, 2018 21:51
WordPress: Expands upon the Custom Meta Boxes library to provide a user-facing input form, list and detail page of submitted forms for custom post types.
<?php
/*
Author: Pete Nelson @GunGeekATX
Expands upon the Custom Meta Boxes library to provide a user-facing input form,
list & detail page of custom post types. This code sample doesn't include all the libraries
such as jQuery tablesorter or validate but can be found elsewhere easily enough.
*/
@petenelson
petenelson / gga-import-joomla-articles.php
Created January 22, 2013 22:23
WordPress: GGA Joomla Content Importer - Imports articles from a Joomla database as WordPress posts
<?php
/*
Plugin Name: GGA Joomla Content Importer
Description: Imports articles from Joomla 1.5x into WordPress
Author: <a href="https://twitter.com/GunGeekATX" target="_blank">@GunGeekATX</a>
Version: 1.1
*/
class ggaJoomlaArticleImporter
@petenelson
petenelson / document.php
Created November 16, 2012 15:50
WordPress: Custom post type (my-document) for docs (PDFs, etc)
<?php
/*
Plugin Name: My Document Permalink
Description: Custom post type (my-document) for docs (PDFs, etc)
Version: 1.0
Author: Pete Nelson
*/
add_action('init', 'my_register_document_post_type');
@petenelson
petenelson / custom-permalink-from-meta.php
Created November 5, 2012 21:32
WordPress permalink for custom post type based on post meta
@petenelson
petenelson / admin_head_post_edit_check.php
Created November 1, 2012 17:03
WordPress admin action hooks for listing/adding/editing posts or pages
/* actions fired when listing/adding/editing posts or pages */
/* admin_head-(hookname) */
add_action( 'admin_head-post.php', 'admin_head_post_editing' );
add_action( 'admin_head-post-new.php', 'admin_head_post_new' );
add_action( 'admin_head-edit.php', 'admin_head_post_listing' );
function admin_head_post_editing() {
echo 'you are editing a post';
}