Skip to content

Instantly share code, notes, and snippets.

@yankiara
yankiara / polylang-init.php
Created Apr 7, 2021
Polylang helpers and translatable strings
View polylang-init.php
<?php
function plang() {
if ( function_exists('pll_current_language') )
return pll_current_language('slug');
else
return 'fr';
}
function phome() {
@yankiara
yankiara / fluentform-dynamic-dropdown.php
Created Aug 21, 2020
Dynamically populate Fluentform dropdown select menu
View fluentform-dynamic-dropdown.php
<?php
add_filter('fluenform_rendering_field_data_select', function ($data, $form) {
if ($form->id != 10)
return $data;
if (\FluentForm\Framework\Helpers\ArrayHelper::get($data, 'attributes.name') != 'poste')
return $data;
$jobs = get_posts( [ 'post_type' => 'job' ] );
@yankiara
yankiara / oxygen-media-breakpoints-buttons.css
Last active Jan 28, 2021
Direct access to Oxygen's media breakpoints
View oxygen-media-breakpoints-buttons.css
.oxygen-media-query-box-wrapper {
position: static;
}
.oxygen-sidebar-currently-editing {
position: relative;
padding-bottom: 48px;
}
.oxygen-media-query-box {
display: none;
}
@yankiara
yankiara / remove-oxygen-imported-alt-text.php
Last active May 17, 2020
Remove imported alt text from Oxygen builder images in all posts/templates
View remove-oxygen-imported-alt-text.php
<?php
/* WARNING: Advanced SQL table modifications, USE AT YOUR OWN RISKS */
/* IMPORTANT: You need to RESIGN SHORTCODES after executing this script */
global $wpdb;
$sql = 'SELECT meta_id, meta_value
FROM ' . $wpdb->postmeta . '
WHERE meta_key = "ct_builder_shortcodes"';
@yankiara
yankiara / gutenberg-columns-gap.css
Created Apr 13, 2020
Custom Gutenberg columns gap
View gutenberg-columns-gap.css
:root {
--columns-gap: 1rem;
}
@media (min-width:782px) {
.wp-block-column:not(:first-child) {
margin-left: var(--columns-gap);
}
}
@media (min-width:600px) and (max-width:781px) {
@yankiara
yankiara / wp-defer-scripts.js
Created Jan 17, 2020
Defer enqueued JS scripts in Wordpress
View wp-defer-scripts.js
add_filter( 'script_loader_tag', 'yankiara_defer_scripts', 10, 3 );
function yankiara_defer_scripts( $tag, $handle, $src ) {
$defer = array( 'script-handle-1', 'script-handle-2', 'script-handle-3' );
if ( in_array( $handle, $defer ) )
return '<script src="' . $src . '" defer="defer" type="text/javascript"></script>' . "\n";
return $tag;
}
@yankiara
yankiara / wordpress-pagination-frontpage.php
Last active Feb 10, 2021
Allow Wordpress posts pagination on frontpage
View wordpress-pagination-frontpage.php
<?php
/*
* Put following code BEFORE running the query (WP loop, Oxygen's repeater, etc.)
* What it does:
* - updates query with right page number variable to display the correct page
* - assigns the query to wp_query so that pagination links work
*/
function handle_pagination_on_frontpage( $query ) {
@yankiara
yankiara / jquery-replace-characters.js
Created Jan 8, 2020
Replace characters in jQuery
View jquery-replace-characters.js
jQuery("h1, h2, h3, h4, h5, h6").each(function() {
jQuery(this).html(function(index, text) {
return text.replace( /([',.;:?!])/g, '<span class="special">$1</span>' );
});
});
@yankiara
yankiara / oxygen-repeater-dynamic-query.php
Last active Apr 8, 2021
Use dynamic queries with Oxygen's repeater
View oxygen-repeater-dynamic-query.php
/* I'll put here different examples of dynamic query for Oxygen repeater :
* - Use one of the following repeater_dynamic_query definitions
* in code block just BEFORE the repeater
* - Set the repeater custom query settings : post type, number of posts, order...
* - Add the remove_action in a code block AFTER the repeater
*/
/****************************************************************************************************
* Display related posts for any CPT with taxonomy:
@yankiara
yankiara / ouput-acf-checkbox-selected.php
Created Dec 31, 2019
Output ACF checkbox field seleted items
View ouput-acf-checkbox-selected.php
<?php
$items = get_field('FIELD_NAME');
if( $items ): ?>
<ul>
<?php foreach( $items as $item ): ?>
<li><?php echo $item; ?></li>
<?php endforeach; ?>
</ul>