Skip to content

Instantly share code, notes, and snippets.

View audrasjb's full-sized avatar

Jb Audras audrasjb

View GitHub Profile
@audrasjb
audrasjb / functions.php
Last active February 2, 2022 12:44
ADEME – Génération d'un flux RSS personnalisé sur WordPress
<?php
function ademe_test_feed_init() {
/*
* Génère un flux personnalisé et détermine une fonction d'affichage.
*
* Le premier paramètre indique l'url du flux généré.
* Le second paramètre détermine la fonction d'affichage associée.
*/
add_feed( 'ademe_press_feed_taxo_theme', 'ademe_press_feed_taxo_theme_response' );
}
@audrasjb
audrasjb / functions.php
Created October 19, 2021 22:36
[polylang] create a shortcode to get the 3 last post, of all available languages
function jba_register_shortcode() {
add_shortcode( 'jba_posts', 'jba_shortcode_cb' );
}
add_action( 'init', 'jba_register_shortcode' );
function jba_shortcode_cb( $args ) {
$args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'tax_query' => '',
@audrasjb
audrasjb / functions.php
Last active October 1, 2021 11:40
Display a script depending on the language of the page (WPML)
// Put this hook in your functions.php file
function jba_analytics_depending_on_language() {
if ( 'en' === ICL_LANGUAGE_CODE ) {
?>
<!-- INSERT YOUR SCRIPT FOR ENGLISH -->
<?php
} elseif ( 'fr' === ICL_LANGUAGE_CODE ) {
?>
<!-- INSERT YOUR SCRIPT FOR FRENCH -->
<?php
@audrasjb
audrasjb / has_block_including_reusables.php
Last active February 5, 2021 16:59
Extend WordPress has_block() function to also check inside Gutenberg reusable blocks
/**
* Determine whether a $post or a string contains a specific block type,
* including blocks that are included in reusable blocks.
*
* @param string $block_name Full Block type to look for.
* @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. Defaults to global $post.
* @return bool Whether the post content contains the specified block.
*/
function has_block_including_reusables( $block_name, $post = false ) {
@audrasjb
audrasjb / functions.php
Last active December 28, 2019 08:42
Replace any translated string in WordPress themes or plugins
<?php
/* Copy this in your child theme functions.php file */
function jba_change_plugin_translations( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Lire plus' :
$translated_text = 'Voir le produit';
break;
}
return $translated_text;
}
@audrasjb
audrasjb / functions.php
Last active July 11, 2022 02:26
Multilingual blog with polylang: query posts in all languages in but only show one version if a post has multiple translations
<?php
/*
* Query all posts versions on home page.
*/
function jba_modify_home_query( $query ) {
if ( function_exists( 'pll__' ) && ! is_admin() && is_home() ) {
$query->set('tax_query', '');
$query->set('lang', '');
}
}