Skip to content

Instantly share code, notes, and snippets.

@alexpani
Last active April 16, 2019 14:06
Show Gist options
  • Save alexpani/5063982 to your computer and use it in GitHub Desktop.
Save alexpani/5063982 to your computer and use it in GitHub Desktop.
Da includere in functions.php
<?php
/**
* functions-genesis.php
* Snippet collection for Genesis powered themes
* Inludes general WP sinippets too
* Author: Alessandro Pani for Active Net
* Version: 2.0
* add to functions.php: require_once('includes/functions-genesis.php');
*/
/********************************************************************************
* Section One: back-end
*********************************************************************************/
/** Remove Genesis default Widgets */
add_action( 'widgets_init', 'ap_remove_genesis_widgets', 20 );
function ap_remove_genesis_widgets() {
unregister_widget( 'Genesis_eNews_Updates' );
unregister_widget( 'Genesis_Featured_Page' );
unregister_widget( 'Genesis_User_Profile_Widget' );
unregister_widget( 'Genesis_Menu_Pages_Widget' );
unregister_widget( 'Genesis_Widget_Menu_Categories' );
unregister_widget( 'Genesis_Featured_Post' );
unregister_widget( 'Genesis_Latest_Tweets_Widget' );
}
/** Remove Genesis in-post SEO Settings */
remove_action( 'admin_menu', 'genesis_add_inpost_seo_box' );
/** Remove Genesis Layout Settings */
remove_theme_support( 'genesis-inpost-layouts' );
/** Remove Genesis menu link */
remove_theme_support( 'genesis-admin-menu' );
/** Remove Genesis SEO Settings menu link */
remove_theme_support( 'genesis-seo-settings-menu' );
/** Remove WP core update notifications */
add_action('admin_menu','ap_remove_wp_update_notifications');
function ap_remove_wp_update_notifications () {
remove_action( 'admin_notices', 'update_nag', 3 );
}
/********************************************************************************
* Section Two: front-end
*********************************************************************************/
/* Enable HTML5 markup */
add_theme_support( 'html5' );
/** Load custom CSS stylesheet to header */
add_action( 'wp_enqueue_scripts', 'load_custom_stylesheet' );
function load_custom_stylesheet() {
wp_enqueue_style( 'custom-stylesheet', CHILD_URL . '/custom.css', array(), PARENT_THEME_VERSION );
}
/** Load custom CSS stylesheet in lieu of default stylesheet to header */
add_filter( 'stylesheet_uri', 'child_stylesheet_uri', 10, 2 );
function child_stylesheet_uri() {
return CHILD_URL . '/custom.css';
}
/** Custom SEO <H1> */
remove_action( 'genesis_site_title', 'genesis_seo_site_title' );
add_action( 'genesis_site_title', 'child_seo_site_title');
function child_seo_site_title() {
echo '<h1 id="title"><a title="Titolo" alt="Titolo" href="http://url">Titolo</a></h1>';
}
/** Responsive meta tag for ios. Prima di attivarlo, verifica che non lo faccia gia' il tema! */
add_action( 'genesis_meta', 'ap_viewport_meta' );
function ap_viewport_meta() {
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0"/>';
}
// Force content-sidebar layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' );
// Force sidebar-content layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_content' );
// Force content-sidebar-sidebar layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar_sidebar' );
// Force sidebar-sidebar-content layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_sidebar_content' );
// Force sidebar-content-sidebar layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_content_sidebar' );
// Force full-width-content layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
/** Add support for custom header */
add_theme_support( 'genesis-custom-header', array( 'width' => 960, 'height' => 90 ), 'textcolor' => '444' );
/** Adding support for custom background */
add_custom_background();
/** Add support for 3-column footer widgets */
add_theme_support( 'genesis-footer-widgets', 3 );
/** Remove the header right widget area */
unregister_sidebar( 'header-right' );
/** Excertp Length */
add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {return 20;}
/** Remove page titles */
add_action( 'get_header', 'an_child_remove_page_titles' );
function an_child_remove_page_titles() {
if ( is_page() && ! is_page_template( 'page_blog.php' ) )
remove_action( 'genesis_post_title', 'genesis_do_post_title' );
}
/** Custom back to top text */
add_filter( 'genesis_footer_backtotop_text', 'ap_backtotop_text' );
function ap_backtotop_text($backtotop) {
$backtotop = '[footer_backtotop text="Torna all\'inizio"]';
return $backtotop;
}
/** Customize Read More Link */
add_filter( 'excerpt_more', 'ap_more_link' );
add_filter( 'get_the_content_more_link', 'ap_more_link' );
add_filter( 'the_content_more_link', 'ap_more_link' );
function ap_more_link($more_link) {
return sprintf('<p><a href="%s" class="more-link">%s</a></span></p>', get_permalink(), 'Leggi tutto');
}
/** Footer credit & attribution text */
add_filter('genesis_footer_creds_text', 'ap_footer_cred');
function ap_footer_cred($bfg_ft) {
$ap_ft = '&copy; ' . date("Y") . ' ' . get_bloginfo("name") .' &middot; Design by <a href="http://www.active-net.it">Active Net</a>.';
return $ap_ft;
}
/** Remove Post Info */
remove_action( 'genesis_before_post_content', 'genesis_post_info' );
/** Customize the post info function */
add_filter( 'genesis_post_info', 'ap_post_info_filter' );
function ap_post_info_filter($post_info) {
if (!is_page()) {
$post_info = '[post_date] by [post_author_posts_link] &middot; [post_comments] [post_edit]';
return $post_info;
}}
/** Remove Post Meta */
remove_action( 'genesis_after_post_content', 'genesis_post_meta' );
/** Customize the post meta function */
add_filter( 'genesis_post_meta', 'ap_post_meta_filter' );
function ap_post_meta_filter($post_meta) {
if (!is_page()) {
$post_meta = '[post_categories before="Filed Under: "] &middot; [post_tags before="Tagged: "]';
return $post_meta;
}}
/** Remove Comments from Posts */
remove_action( 'genesis_after_post', 'genesis_get_comments_template' );
/** Move primary nav menu */
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_before_header', 'genesis_do_nav' );
/** Move secondary nav menu */
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_before_header', 'genesis_do_subnav' );
/**
* Add Genesis custom support for registered post types
* Add Genesis SEO/Layout support to CPTs (if not registered with them)
*/
add_action( 'init', 'wps_add_post_type_support' );
function wps_add_post_type_support() {
add_post_type_support( 'post_type', 'genesis-seo' );
add_post_type_support( 'post_type', 'genesis-layouts' );
add_post_type_support( 'post_type', 'genesis-simple-sidebars' );
}
/** Register a sidebar */
genesis_register_sidebar( array(
'id' => 'before-content-area',
'name' => __( 'Before Content Area', 'child' ),
'description' => __( 'Area precedente i post', 'child' ),
) );
add_action( 'genesis_before_post', 'child_before_content_area_sidebar' );
function child_before_content_area_sidebar() {
echo '<div class="before-content-area">';
dynamic_sidebar( 'before-content-area' );
echo '</div>';
}
/* Add support for structural wraps. Verificare che non lo imposti gia' il tema! */
add_theme_support( 'genesis-structural-wraps', array( 'header', 'nav', 'subnav', 'inner', 'footer-widgets', 'footer' ) );
/** Unregister site layouts */
genesis_unregister_layout( 'content-sidebar' );
genesis_unregister_layout( 'sidebar-content' );
genesis_unregister_layout( 'content-sidebar-sidebar' );
genesis_unregister_layout( 'sidebar-sidebar-content' );
genesis_unregister_layout( 'sidebar-content-sidebar' );
genesis_unregister_layout( 'full-width-content' );
/** Remove default image sizes */
add_filter('image_size_names_choose', 'ap_remove_all_image_sizes');
function ap_remove_all_image_sizes($sizes) {
// questi update in teoria non sono neccessari, di fatto così sono sicuro del risultato
update_option( 'thumbnail_size_h', 0 );
update_option( 'thumbnail_size_w', 0 );
update_option( 'medium_size_h', 0 );
update_option( 'medium_size_w', 0 );
update_option( 'large_size_h', 0 );
update_option( 'large_size_w', 0 );
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['large']);
// unset( $sizes['full'] );
return $sizes;
}
/** Add custom image sizes */
add_image_size('magazine-thumb', 120, 120, true); //crop
// add_image_size('slideshow-thumb', 250, 220, false);
// add_image_size('sidebar-thumb', 85, 85, true); //crop
/** Relocate the breadcrumbs */
remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' );
add_action( 'genesis_after_header', 'genesis_do_breadcrumbs' );
/** Remove Home from Breadcrumbs */
add_filter('genesis_home_crumb', '__return_false');
/** Customize breadcrumb arguments */
add_filter( 'genesis_breadcrumb_args', 'child_breadcrumb_args' );
function child_breadcrumb_args( $args ) {
$args['home'] = 'Home';
$args['sep'] = ' / ';
$args['list_sep'] = ', '; // Genesis 1.5 and later
$args['prefix'] = '<div class="breadcrumb">';
$args['suffix'] = '</div>';
$args['heirarchial_attachments'] = true; // Genesis 1.5 and later
$args['heirarchial_categories'] = true; // Genesis 1.5 and later
$args['display'] = true;
$args['labels']['prefix'] = 'You are here: ';
$args['labels']['author'] = 'Archives for ';
$args['labels']['category'] = 'Archives for '; // Genesis 1.6 and later
$args['labels']['tag'] = 'Archives for ';
$args['labels']['date'] = 'Archives for ';
$args['labels']['search'] = 'Search for ';
$args['labels']['tax'] = 'Archives for ';
$args['labels']['post_type'] = 'Archives for ';
$args['labels']['404'] = 'Not found: '; // Genesis 1.5 and later
return $args;
}
/** Add custom text for search button **/
add_filter('genesis_search_button_text', 'an_custom_search_button_text');
function an_custom_search_button_text($text) {
return esc_attr('Cerca');
}
/** Customize Search Form Text **/
add_filter('genesis_search_text', 'an_custom_search_text');
function an_custom_search_text( $text ) {
return esc_attr( 'Cerca nel sito...' );
}
/** Remove Edit Link */
add_filter( 'edit_post_link', '__return_false' );
/** Define Jpeg Compression quality (default: 90) */
add_filter('jpeg_quality', 'jpeg_quality_callback');
function jpeg_quality_callback($arg) {
return (int)100;
}
/** Add Google Authorship to HEAD */
add_action( 'wp_head', 'ap_google_authorship', 99 );
function ap_google_authorship() {?><link rel="author" href="https://plus.google.com/XXXXXXXXXXXX">';<?php
}
/** Remove the Feed system */
remove_theme_support( 'automatic-feed-links' );
/** Email Tweaks */
add_filter( 'wp_mail_from', 'new_mail_from' );
function new_mail_from( $from ) {
$from = 'My Cool WordPress Site';
return $from;
}
/* Email sender */
add_filter( 'wp_mail_from_name', 'new_mail_from_name' );
function new_mail_from_name( $email ) {
$email = '[email protected]';
return $email;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment