Skip to content

Instantly share code, notes, and snippets.

Avatar

Jon Schroeder jonschr

View GitHub Profile
View functions.php
add_action( 'wp_enqueue_scripts', 'rb_register_scripts' );
function rb_register_scripts() {
wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css', array(), CHILD_THEME_VERSION );
wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800,400italic', array(), CHILD_THEME_VERSION );
wp_enqueue_style( 'tackett', get_bloginfo( 'stylesheet_directory' ) . '/css/terra.css' );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-tabs' );
wp_enqueue_script( 'tabs', get_bloginfo( 'stylesheet_directory' ) . '/js/tabs.js', array( 'jquery' ) );
@jonschr
jonschr / script.js
Created Jan 4, 2016
Scripts to pull in oil and natural gas prices
View script.js
<script type="text/javascript" src="http://www.oil-price.net/TABLE3/gen.php?lang=en"></script><noscript> To get the <a href="http://www.oil-price.net/dashboard.php?lang=en#TABLE3">oil price</a>, please enable Javascript.</noscript>
<!-- <script type="text/javascript" src="http://www.oil-price.net/widgets/brent_text/gen.php?lang=en"></script><noscript> To get the <a href="http://www.oil-price.net/dashboard.php?lang=en#BRENT_TEXT">oil price</a>, please enable Javascript.</noscript> -->
<script type="text/javascript" src="http://www.oil-price.net/widgets/natural_gas_text/gen.php?lang=en"></script><noscript> To get the <a href="http://www.oil-price.net/dashboard.php?lang=en#NATURAL_GAS_TEXT">natural gas price</a>, please enable Javascript.</noscript>
@jonschr
jonschr / script.js
Created Nov 10, 2015
Adding a copyright symbol every time an instance of a word is used (for use on a site where we needed that copyright added throughout automatically)
View script.js
jQuery(document).ready(function( $ ) {
$("body *").replaceText( /Hold Me Tight/gi, "Hold Me Tight<span class='trademark'>&reg;</span>" );
});
@jonschr
jonschr / new_gist_file.js
Created Nov 10, 2015
A javascript snippet to wrap just one word with a container
View new_gist_file.js
jQuery(document).ready(function( $ ) {
$('.word-highlight').each(function() {
var word = $(this).html();
var index = word.indexOf(' ');
if(index == -1) {
index = word.length;
}
$(this).html('<span class="first-word">' + word.substring(0, index) + '</span>' + word.substring(index, word.length));
});
@jonschr
jonschr / plugin.php
Last active Nov 5, 2015
A snippet to assign a child theme template file if there is one for archive-cpt.php, fall back to the plugin file (archive-cpt.php) if not, and if there's no file in the plugin, then fall back to the default Wordpress template hierarchy.
View plugin.php
<?php
//* Don't include the opening php tag
/**
* Return Section (for template selection)
* @link http://www.billerickson.net/code/helper-function-for-template-include-and-body-class/
*
* @param null
* @return string
*/
@jonschr
jonschr / functions.php
Created Nov 3, 2015
Assigning sidebars programatically
View functions.php
<?php
// Don't include the opening php tag
/**
* Assign the sidebars
*/
add_action( 'genesis_header','prefix_change_genesis_sidebar' );
function prefix_change_genesis_sidebar() {
global $post;
View functions.php
<?php
// Don't include the opening php tag
// Add a tracking script to a particular page, just before the </body> tag
add_action( 'wp_footer', 'tj_add_tracking_scripts' );
function tj_add_tracking_scripts() {
global $post;
if ( is_page( 'your-page-slug' ) ) {
?>
@jonschr
jonschr / functions.php
Created Oct 21, 2015
Modifying a query before it begins
View functions.php
<?php
// Don't include the opening php tag
// Modify a query conditionally in functions.php
function prefix_modify_query( $query ) {
if ( $query->is_home() && $query->is_main_query() && !is_admin() ) {
$query->set( 'post_type', 'my_cpt_name' );
}
}
add_action( 'pre_get_posts', 'prefix_modify_query' );
@jonschr
jonschr / new_gist_file_0
Created Oct 21, 2015
Remove the 'tag' capability from posts
View new_gist_file_0
<?php
// Don't include the opening php tag
// Remove tags support from posts
function prefix_unregister_tags() {
unregister_taxonomy_for_object_type( 'post_tag', 'post' );
}
add_action('init', 'prefix_unregister_tags' );
@jonschr
jonschr / functions.php
Created Oct 19, 2015
Remove the author box in a template file
View functions.php
<?php
//* Don't include the opening php tag
//* Remove the author box on single posts HTML5 Themes
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );