Skip to content

Instantly share code, notes, and snippets.

View fenda's full-sized avatar

Fernanda Sampaio fenda

View GitHub Profile
preSelect(fieldSelector, optionValues) {
console.log("run this...");
[...optionValues].map((value) => {
jQuery(`${fieldSelector} option[value=${value}]`).attr('selected', 'selected');
});
jQuery(`${fieldSelector}`).trigger('chosen:updated');
}
// usage
// GRAVITY_FORM.preSelect(DATA.formFieldSelector, [marketingId]);
const programCards = document.querySelectorAll('.card-squared-programme');
if (programCards) {
programCards.forEach(function (card, index) {
const mktID = card.dataset.marketingId;
const productList = document.querySelector('#input_1_5-ts-control');
card.addEventListener('click', function (event) {
console.log(mktID);
productList.click();
})
});
" Make IE Better Compatible "
<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
======================================================
IE6 Only
==================
_selector {...}
@fenda
fenda / .htaccess
Created July 31, 2018 18:52
Remove extension from webpages
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
<?php if ( get_field( 'field_name' ) ): ?>
This is displayed when the field_name is TRUE or has a value.
<?php else: // field_name returned false ?>
This is displayed when the field is FALSE, NULL or the field does not exist.
<?php endif; // end of if field_name logic ?>
@fenda
fenda / remove_query_strings.php
Created February 11, 2018 11:02
Remove Query Strings From Static Resources With Code
function _remove_script_version( $src ){
$parts = explode( '?', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
//https://kinsta.com/knowledgebase/remove-query-strings-static-resources/#remove-query-string-code
@fenda
fenda / user_role_content.php
Created February 4, 2018 11:06
Add content based on user role
<?php global $user_login, $current_user;
if (is_user_logged_in()) {
get_currentuserinfo();
$user_info = get_userdata($current_user->ID);
if (in_array('subscriber', $user_info->roles)) {
?>
Content goes here
<?php
}
@fenda
fenda / iphone.html
Created January 17, 2018 19:46
iPhone X media query
<meta name="viewport" content="width=device-width,minimum-scale=1.0,initial-scale=1.0,maximum-scale=1.0,user-scalable=no,viewport-fit=cover">
@fenda
fenda / wordpress_admin_page.php
Created December 28, 2017 19:29
Page visible to admin only
<?php global $user_ID; if( $user_ID ) : ?>
<?php if( current_user_can('activate_plugins') ) : ?>
<!-- CONTENT HERE -->
<?php endif; ?>
<?php endif; ?>
@fenda
fenda / acf_image_crop.php
Last active December 28, 2017 19:30
ACF image with crop size
<?php
$attachment_id = get_field('field_name');
$size = "full"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
?>
<img class="image-class" alt="" src="<?php echo $image[0]; ?>" />