Skip to content

Instantly share code, notes, and snippets.

View jonschr's full-sized avatar

Jon Schroeder jonschr

View GitHub Profile
@jonschr
jonschr / functions.php
Created October 19, 2015 00:15
Display a widget somewhere on a site (this example shows it before the footer)
<?php
//* Don't include the opening php tag
//* Display a widget area before the footer
add_action( 'genesis_before_footer', 'prefix_show_your_widget_area' );
function prefix_show_your_widget_area () {
genesis_widget_area( 'your-widget-area', array(
'before' => '<div>', // markup before the widget
'after' => '</div>', // markup after the widget
) );
@jonschr
jonschr / functions.php
Created October 19, 2015 00:19
Filter the footer text and replace it with some of out own
<?php
//* Don't include the opening php tag
//* Filter the footer credits
add_filter( 'genesis_footer_creds_text', 'prefix_footer_creds_text' );
function prefix_footer_creds_text( $args ) {
$args = '[footer_copyright] ' . get_bloginfo( 'name' ) . '<br/>Website handcrafted with love by Your Name';
return $args;
}
@jonschr
jonschr / functions.php
Created October 19, 2015 00:46
Set the content width
<?php
//* Don't include the php tag
//* Set the content width
if ( ! isset( $content_width ) ) {
$content_width = 840;
}
@jonschr
jonschr / functions.php
Created October 19, 2015 03:52
Remove the author box in a template file
<?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 );
@jonschr
jonschr / new_gist_file_0
Created October 21, 2015 09:21
Remove the 'tag' capability from posts
<?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 October 21, 2015 09:37
Modifying a query before it begins
<?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' );
<?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 November 3, 2015 05:02
Assigning sidebars programatically
<?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;
@jonschr
jonschr / plugin.php
Last active November 5, 2015 17:21
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.
<?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 / new_gist_file.js
Created November 10, 2015 08:35
A javascript snippet to wrap just one word with a container
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));
});