Skip to content

Instantly share code, notes, and snippets.

@gregoirenoyelle
Last active July 13, 2017 13:03
Show Gist options
  • Save gregoirenoyelle/51b1391456216d552590 to your computer and use it in GitHub Desktop.
Save gregoirenoyelle/51b1391456216d552590 to your computer and use it in GitHub Desktop.
Genesis Functions
<?php
/*
Zone Auteur
---------------------------------------------------------------------------------------------------- */
/** Retirer la zone auteur sur les single */
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single' );
/** Afficher la zone auteur sur les singles */
add_filter( 'get_the_author_genesis_author_box_single', '__return_true' );
/** Afficher la zone auteur sur les archives */
add_filter( 'get_the_author_genesis_author_box_archive', '__return_true' );
add_filter( 'genesis_author_box_title', 'gs_author_box_title' );
/**
* Modify author box title
*
* @param string $title Default title (default: About {the author's name}).
* @return string New author box title.
*/
function gs_author_box_title( $title ) {
return '<strong>A propos de l\'Auteur</strong>';
}
add_filter( 'genesis_author_box_gravatar_size', 'gs_author_box_gravatar_size', 10, 2 );
/**
* Modify the size of the Gravatar in author box
*
* @param int $size Size in pixels of gravatar (default: 70).
* @param string $context Optional. Allows different author box markup for
* different contexts, specifically 'single'. Default is empty string.
* @return int New size in pixels of gravatar.
*/
function gs_author_box_gravatar_size( $size, $context ) {
return 80;
}
<?php
/*
Ajouter des classes au Body et au post
---------------------------------------------------------------------------------------------------- */
add_filter( 'body_class', 'gs_add_body_class' );
/**
* Add custom body class to the head.
*
* @param array $classes Array of existing body classes.
* @return array $classes Modified Array of body classes.
*/
function gs_add_body_class( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
add_filter( 'post_class', 'gs_post_class' );
/**
* Add custom post classes.
*
* @param array $classes Array of existing post classes.
* @return array $classes Modified Array of body classes.
*/
function gs_post_class( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
<?php
/*
Changer la largeur du contenu pour la page 467 et pour les page des fichiers média
---------------------------------------------------------------------------------------------------- */
add_filter('template_redirect', 'gn_custom_content_width_embed_size');
function gn_custom_content_width_embed_size($embed_size){
if ( is_page(467) || is_attachment() ) {
global $content_width;
$content_width = 960;
}
}
<?php
/*
Changer le Doctype
---------------------------------------------------------------------------------------------------- */
remove_action( 'genesis_doctype', 'genesis_do_doctype' );
add_action( 'genesis_doctype', 'gs_do_doctype' );
/**
* Conditional html element classes
*/
function child_do_doctype() {
?>
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html class="ie6" xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes( 'xhtml' ); ?>> <![endif]-->
<!--[if IE 7 ]> <html class="ie7" xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes( 'xhtml' ); ?>> <![endif]-->
<!--[if IE 8 ]> <html class="ie8" xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes( 'xhtml' ); ?>> <![endif]-->
<!--[if IE 9 ]> <html class="ie9" xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes( 'xhtml' ); ?>> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class="" xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes( 'xhtml' ); ?>> <!--<![endif]-->
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php bloginfo( 'charset' ); ?>" />
<?php
}
<?php
/*
Intégrer les Google fonts
---------------------------------------------------------------------------------------------------- */
add_action( 'wp_enqueue_scripts', 'gs_load_google_fonts' );
/**
* Enqueue Google fonts
*/
function gs_load_google_fonts() {
wp_enqueue_style(
'child-google-fonts',
'http://fonts.googleapis.com/css?family=Merriweather|Open+Sans',
array(),
CHILD_THEME_VERSION
);
}
<?php
/*
Options de mise en page
---------------------------------------------------------------------------------------------------- */
/**** Force la mise en page. L'utilisateur ne peux pas changer ****/
// Maquette Pleine largeur
add_filter( 'genesis_site_layout', '__genesis_return_full_width_content' );
// Maquette Contenu | Barre latérale
add_filter( 'genesis_site_layout', '__genesis_return_content_sidebar' );
// Maquette Barre latérale | Contenu
add_filter( 'genesis_site_layout', '__genesis_return_sidebar_content' );
// Maquette Contenu | Barre latérale | Barre latérale
add_filter( 'genesis_site_layout', '__genesis_return_content_sidebar_sidebar' );
// Maquette Barre latérale | Barre latérale | Contenu
add_filter( 'genesis_site_layout', '__genesis_return_sidebar_sidebar_content' );
// Maquette Barre latérale| Contenu | Barre latérale
add_filter( 'genesis_site_layout', '__genesis_return_sidebar_content_sidebar' );
/**** Propose la mise en page. L'utilisateur peux modifier ****/
// Maquette Pleine largeur
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
// Maquette Contenu | Barre latérale
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' );
// FMaquette Barre latérale | Contenu
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_content' );
// Maquette Contenu | Barre latérale | Barre latérale
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar_sidebar' );
// Maquette Barre latérale | Barre latérale | Contenu
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_sidebar_content' );
// Maquette Barre latérale| Contenu | Barre latérale
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_content_sidebar' );
<?php
/*
Supprimer les metaboxes
---------------------------------------------------------------------------------------------------- */
/** Enlever les options SEO dans chaque contenu */
remove_action( 'admin_menu', 'genesis_add_inpost_seo_box' );
/** Enlever les options de maquette dans chaque contenu */
remove_theme_support( 'genesis-inpost-layouts' );
<?php
/*
Changer la position des éléments: Fil d'ariane, Pied de page, Barre latérale 1 et 2
---------------------------------------------------------------------------------------------------- */
/** Changer la position du fil d'Ariane */
remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' );
add_action( 'genesis_after_header', 'genesis_do_breadcrumbs' );
/** Changer la position du footer */
/* je retire et je remets à un endroit différent */
remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 );
remove_action( 'genesis_footer', 'genesis_do_footer' );
remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 );
add_action( 'genesis_after', 'genesis_footer_markup_open', 11 );
add_action( 'genesis_after', 'genesis_do_footer', 12 );
add_action( 'genesis_after', 'genesis_footer_markup_close', 13 );
/** Changer la position de la navigation primaire */
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_before_header', 'genesis_do_nav' );
/** Changer la position de la navigation secondaire */
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_before_header', 'genesis_do_subnav' );
<?php
/*
Info et Meta des articles
---------------------------------------------------------------------------------------------------- */
add_filter( 'genesis_post_info', 'gs_post_info_filter' );
/**
* Customize the post info function
*
* @link http://my.studiopress.com/docs/shortcode-reference/
* @param string $post_info Default post info.
* (default: '[post_date] ' . __( 'by', 'genesis' ) . ' [post_author_posts_link] [post_comments] [post_edit]')
* @return string Modified post info.
*/
function gs_post_info_filter( $post_info ) {
return '[post_date] by [post_author_posts_link] [post_comments] [post_edit]';
}
/** Supprimer les post info */
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
add_filter( 'genesis_post_meta', 'gs_post_meta_filter' );
/**
* Customize the post meta function
*
* @link http://my.studiopress.com/docs/shortcode-reference/
* @param string $post_meta Default post meta.
* (default: '[post_categories] [post_tags]')
* @return string Modified post meta.
*/
function gs_post_meta_filter( $post_meta ) {
return '[post_categories before="Filed Under: "] [post_tags before="Tagged: "]';
}
/** Suprimer les post meta */
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
<?php
/*
Editer les Extrait/Contenu avec en lire plus
---------------------------------------------------------------------------------------------------- */
// Changer le lien pour en lire plus pour les extraits
/**
* Edit excerpt read more link
*
* @param string $more Read More Text, , default: ' ' . '[...]'
* @return string Modified Read More Text.
*/
function gs_remove_excerpt_more( $more ) {
return '...';
}
// Changer le lien pour en lire plus
/**
* Edit read more link.
*
* @param string $link HTML Read More Link, default: sprintf( '&#x02026; <a href="%s" class="more-link">%s</a>', get_permalink(), $more_link_text = '(more...)' ).
* @return string Modified HTML Read More Link.
*/
function gs_read_more_link( $link ) {
return '<a class="more-link" href="' . get_permalink() . '" rel="nofollow">Read More</a>';
}
<?php
/*
Retirer le tailles d'image par défaut
---------------------------------------------------------------------------------------------------- */
add_filter( 'intermediate_image_sizes_advanced', 'gs_remove_image_sizes' );
/**
* Remove WordPress Image Sizes.
*
* @param array $sizes Array of Intermediate Image Sizes.
* @return array $sizes Modified Array of Intermediate Image Sizes.
*/
function gs_remove_image_sizes( $sizes ) {
unset( $sizes['thumbnail'] );
unset( $sizes['medium'] );
unset( $sizes['large'] );
return $sizes;
}
<?php
/*
Supprimer les menus Genesis
---------------------------------------------------------------------------------------------------- */
/** Enlever le menu Genesis */
remove_theme_support( 'genesis-admin-menu' );
/** Enlever le menu SEO de Genesis */
remove_theme_support( 'genesis-seo-settings-menu' );
/** Enlever le menu de support */
remove_theme_support( 'genesis-readme-menu' );
<?php
/*
Supprimer les widgets WordPress/Genesis
---------------------------------------------------------------------------------------------------- */
add_action( 'widgets_init', 'gn_remove_selected_widget', 20 );
/**
* Remove Genesis/WordPress widgets
*/
function gn_remove_selected_widget() {
// Retirer widget Page à la Une
unregister_widget( 'Genesis_Featured_Page' );
// Retirer widget Article à la Une
unregister_widget( 'Genesis_Featured_Post' );
// Retirer widget Page Auteur
unregister_widget( 'Genesis_User_Profile_Widget' );
// Retirer les widget WordPress
//unregister_widget( 'WP_Widget_Pages' );
//unregister_widget( 'WP_Widget_Calendar' );
//unregister_widget( 'WP_Widget_Archives' );
//unregister_widget( 'WP_Widget_Links' );
//unregister_widget( 'WP_Widget_Meta' );
//unregister_widget( 'WP_Widget_Search' );
//unregister_widget( 'WP_Widget_Text' );
//unregister_widget( 'WP_Widget_Categories' );
//unregister_widget( 'WP_Widget_Recent_Posts' );
//unregister_widget( 'WP_Widget_Recent_Comments' );
//unregister_widget( 'WP_Widget_RSS' );
//unregister_widget( 'WP_Widget_Tag_Cloud' );
//unregister_widget( 'WP_Nav_Menu_Widget' );
}
<?php
/*
Champ et bouton de recherche
---------------------------------------------------------------------------------------------------- */
// Changer le texte dans le champ de recherche
add_filter( 'genesis_search_text', 'gs_search_text' );
/**
* Customize search form input box text
*
* @param string $text Default search form input box text.
* (default: esc_attr__( 'Search this website', 'genesis' ) . '&#x02026;' )
* @return string Modified search form input box text.
*/
function gs_search_text($text) {
return esc_attr( 'Search my blog...' );
}
// Changer le texte du bouton
add_filter( 'genesis_search_button_text', 'gs_search_button_text' );
/**
* Customize search form input button text
*
* @param string $text Default search form input button text.
* (default: Search )
* @return string Modified search form input button text.
*/
function gs_search_button_text($text) {
return esc_attr( 'Go' );
}
Post Shortcodes
[post_date]
[post_time]
[post_author]
[post_author_link]
[post_author_posts_link]
[post_comments]
[post_tags]
[post_categories]
[post_edit]
[post_terms]
Footer Shortcodes
[footer_copyright]
[footer_childtheme_link]
[footer_genesis_link]
[footer_studiopress_link]
[footer_wordpress_link]
[footer_loginout]
<?php
/*
Titre du site, description, entête de droite
---------------------------------------------------------------------------------------------------- */
/** Supprimer le titre du site */
remove_action( 'genesis_site_title', 'genesis_seo_site_title' );
/** Supprimer la description du site */
remove_action( 'genesis_site_description', 'genesis_seo_site_description' );
/** Supprimer l'entête de droite */
unregister_sidebar( 'header-right' );
/*
Changer le lien du titre ou du logo (version HTML5)
---------------------------------------------------------------------------------------------------- */
function gn_logo_url( $title, $inside, $wrap ) {
$home = get_bloginfo('url' ) . '/votre-page/';
$name = get_bloginfo( 'name' );
$inside = sprintf( '<a href="%s" title="%s">%s</a>', esc_url( $home ), esc_attr( $name ), $name );
$title = sprintf( '<%s class="site-title" itemprop="headline">%s</%s>', $wrap, $inside, $wrap );
return $title;
}
add_filter( 'genesis_seo_title', 'gn_logo_url', 10, 3 );
<?php
/*
Ajouter des supports pour les custom post type
---------------------------------------------------------------------------------------------------- */
// 'genesis-seo', 'genesis-cpt-archives-settings', 'genesis-layouts'
$genesis_supports = array('genesis-seo', 'genesis-cpt-archives-settings', 'genesis-layouts');
add_post_type_support( $post_type, $genesis_supports);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment