Skip to content

Instantly share code, notes, and snippets.

View adambradford's full-sized avatar

Adam Bradford adambradford

View GitHub Profile
@adambradford
adambradford / functions.php
Created March 21, 2018 14:48
Ensure WooCommerce cart contents update when products are added to the cart via AJAX
<?php
//* Add this to your functions.php file. Do NOT include the opening php tag
// Ensure cart contents update when products are added to the cart via AJAX
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
ob_start();
?>
@adambradford
adambradford / functions.php
Created March 21, 2018 14:57
Add a "Formats" drop-down for styling text to the WordPress TinyMCE editor
<?php
//* Add this to your functions.php file. Do NOT include the opening php tag
//* Add the "Formats" drop-down in the WP editor
add_filter( 'mce_buttons_2', 'ab_mce_editor_buttons' );
function ab_mce_editor_buttons( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
@adambradford
adambradford / functions.php
Created March 21, 2018 16:08
Add an After Footer area in a WordPress site built with the Genesis Framework
<?php
//* Add this to your functions.php file. Do NOT include the opening php tag
//* Add After Footer area
add_action( 'genesis_after_footer', 'include_after_footer' );
function include_after_footer() {
require(CHILD_DIR.'/after-footer.php');
}
@adambradford
adambradford / functions.php
Created March 21, 2018 16:09
Add Before Sidebar widget area in a WordPress site built with the Genesis Framework
<?php
//* Add this to your functions.php file. Do NOT include the opening php tag
//* Add Before Sidebar widget area
genesis_register_sidebar( array(
'id' => 'before-sidebar',
'name' => __( 'Before Sidebar', 'themename' ),
'description' => __( 'This is a widget area that can be placed above the sidebar', 'themename' ),
) );
@adambradford
adambradford / functions.php
Created March 21, 2018 16:13
Add Dashicon to search form button in a WordPress site built with the Genesis Framework
<?php
//* Add this to your functions.php file. Do NOT include the opening php tag
//* Add Dashicon to search form button
add_filter( 'genesis_search_button_text', 'ab_search_button_icon' );
function ab_search_button_icon( $text ) {
return esc_attr( '&#xf002;' );
}
@adambradford
adambradford / functions.php
Created March 21, 2018 16:19
Allow the standard WordPress text widget to execute PHP
<?php
//* Add this to your functions.php file. Do NOT include the opening php tag
//* Allow Standard WordPress Text widget to execute PHP
function php_execute($html){
if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
@adambradford
adambradford / functions.php
Last active March 26, 2018 20:47
Add Before Footer widget area in a WordPress site built with the Genesis Framework
<?php
//* Add this to your functions.php file. Do NOT include the opening php tag
//* Add a Before Footer widget area
genesis_register_sidebar( array(
'id' => 'before-footer',
'name' => __( 'Before Footer' ),
'description' => __( 'This is the area just above the footer', 'genesis' ),
) );
@adambradford
adambradford / functions.php
Last active April 9, 2018 10:20
Change the footer content in a WordPress site built with the Genesis Framework
<?php
//* Add this to your functions.php file. Do NOT include the opening php tag
//* Change the footer content
add_filter('genesis_footer_creds_text', 'ab_footer_creds_filter');
function ab_footer_creds_filter( $creds ) {
$creds = '[footer_copyright] <a href="http://www.example.com">Your Name</a>';
return $creds;
}
@adambradford
adambradford / functions.php
Last active March 30, 2018 15:34
Display Custom Post Type in WordPress Author Archive
<?php
//* Add this to your functions.php file. Do NOT include the opening php tag
// Display Custom Post Type in Author Archive
function post_types_author_archives($query) {
if ($query->is_author)
// Allow 'my_custom_post_type' CPT and the default 'posts' to display in author's archive
$query->set( 'post_type', array('my_custom_post_type', 'posts') );
remove_action( 'pre_get_posts', 'custom_post_author_archive' );
}
@adambradford
adambradford / functions.php
Created March 21, 2018 16:26
Reposition the primary navigation menu in WordPress site built with Genesis framework
<?php
//* Add this to your functions.php file. Do NOT include the opening php tag
//* Reposition the primary navigation menu
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_header', 'genesis_do_nav', 12 );