Skip to content

Instantly share code, notes, and snippets.

View larodiel's full-sized avatar

Victor Larodiel larodiel

View GitHub Profile
@larodiel
larodiel / index.php
Created April 6, 2021 04:24
ACF meta query to exclude posts
<?php
// WP_Query arguments
$args = array(
'post_type' => 'post',
'post_status' => array( 'publish' ),
'posts_per_page' => -1,
'ignore_sticky_posts' => true,
'meta_query' => array(
'relation' => 'OR',
@larodiel
larodiel / functions.php
Created April 2, 2022 05:48
Load a single post page based on the category (can be adapted to taxonomy)
<?php
/**
* Load Single Page by Category
*/
add_filter('single_template', function ($template) {
foreach ((array) get_the_category() as $cat) {
$templateFile = STYLESHEETPATH . "/single-category-{$cat->slug}.php";
if (file_exists($templateFile)) {
@larodiel
larodiel / functions.php
Created November 13, 2023 11:50
Limit Wordpress RSS Items using parameters
<?php
add_action('pre_get_posts', function($query) {
if ($query->is_feed() && filter_input(INPUT_GET, 'count', FILTER_VALIDATE_INT) && filter_input(INPUT_GET, 'count', FILTER_VALIDATE_INT)) {
$query->set('posts_per_rss', filter_input(INPUT_GET, 'count', FILTER_VALIDATE_INT));
}
return $query;
});
@larodiel
larodiel / .gitignore_global
Created March 4, 2023 05:48
Global gitignore
# -----------------------------------------------------------------
# ver 1.1.0
#
# Change Log:
# 20160721 - First version
# 20171018 - error_log added
# -----------------------------------------------------------------
# ignore all files starting with . or ~
.*
@larodiel
larodiel / functions.php
Created December 13, 2022 01:53
Set the ACF SYNC path on sage template
<?php
add_filter('acf/settings/save_json', function($path) {
return get_stylesheet_directory() . '/acf-json';
});
add_filter('acf/settings/load_json', function($paths) {
unset($paths[0]);
$paths[] = get_stylesheet_directory() . '/acf-json';
return $paths;
@larodiel
larodiel / functions.php
Last active December 13, 2022 01:51
Add the colors that are on WP theme.json on ACF Color pick
<?php
add_action('acf/input/admin_footer', function() {
$themeJsonFile = get_stylesheet_directory() . '/theme.json';
if(file_exists($themeJsonFile)) {
$themeJson = json_decode(file_get_contents($themeJsonFile));
$colorsArray = [];
$colorsJson = '';
foreach($themeJson->settings->color->palette as $color) {
$colorsArray[] = $color->color;
@larodiel
larodiel / functions.php
Last active April 2, 2022 05:56
Some helpful WordPress functions
<?php
/**
* Enqueue scripts and styles.
*/
function lrd_load_assets() {
wp_enqueue_style('fontawesome',"https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" );
wp_enqueue_style( 'cd-extra-style', get_stylesheet_directory_uri()."/css/extra.css" );
if( is_testing() ) {
//test code here
}
else {
//original code here
}
/**
* Using query param
* http://example.com?testing=nav
@larodiel
larodiel / regex.txt
Last active November 11, 2021 20:37
Useful regEx
USER_NAME = "^[A-Za-z0-9_-]{min number of character,max number of character}$";
TELEPHONE = "(^\\+)?[0-9()-]*";
TELEPHONE_OPTIONAL = "^($|(^\\+)?[0-9()-]*)$"
EMAIL = "^([a-zA-Z0-9\.\_\+\-]+)@([a-zA-Z0-9\-]+)(\.[a-zA-Z]+)+$";
EMAIL_OPTIONAL = "^($|[a-zA-Z0-9_\\.\\+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-\\.]+)$";
@larodiel
larodiel / JS-vanilla-keep-video-proportion.js
Last active September 2, 2021 05:47
Get iframe videos and keep it proportion based on a parent container.
let videoProportionResize = (videoContainer) => {
const videos = document.querySelectorAll("iframe[src*='youtube.com'], iframe[src*='vimeo.com'], iframe[src*='twitch.tv']");
if(videos.length === 0) {
console.log('no videos found');
return false;
}
videoContainer = typeof videoContainer !== 'undefined' ? document.querySelector(videoContainer) : videos[0].parentNode;
const containerWidth = videoContainer.offsetWidth;