Skip to content

Instantly share code, notes, and snippets.

@Farmatique
Farmatique / gist:eff45bb3438e4e9b2f5c544e831a86c1
Last active September 4, 2019 08:35
Regexp. Search if text contains One AND Two words. contains a set of words
// from here https://www.regular-expressions.info/completelines.html
^(?=.*?\bfirst_word\b)(?=.*?\bsecond_word\b).*$
@Farmatique
Farmatique / gist:840f0b09df91b487a575ae9857cff629
Created September 3, 2019 19:03
Shortify text, make short text, make excerpt using jQuery
var text = "This is your title";
var shortText = jQuery.trim(text).substring(0, 10)
.split(" ").slice(0, -1).join(" ") + "...";
@Farmatique
Farmatique / gist:4ee707844ec3ba6f6a4209293f48e4ae
Created August 29, 2019 19:35
Wordpress php get JSON data from API fetch data
<?php
$url = "https://endpoint.api";
$username = "username";
$password = "password";
$args = array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password )
)
);
@Farmatique
Farmatique / gist:475c3470572b798f7542d845ca010337
Created August 27, 2019 11:45
Select HTML of element in jquery including element itself (wrapper)
jQuery('.element').prop('outerHTML'); // return html of element including element itself
@Farmatique
Farmatique / gist:c7e90f2107de21663e27673f125cbf58
Created August 16, 2019 15:24
Get index within Wordpress posts loop
<?php $index = 0; while (have_posts()) : the_post(); ?>
<?php get_template_part('partials/content', get_post_type() != 'post' ? get_post_type() : get_post_format()); ?>
<div class="temp-index"><?=$index;?></div>
<?php $index++;endwhile; ?>
@Farmatique
Farmatique / gist:9d5d6288c114e081f23a940e4dd6fdbc
Created July 31, 2019 21:48
Wordpress. Exclude post category from homepage or blog
//Remember the ID number of the category (in this case, the number is 55)
//Open functions.php file from the active theme
//Copy and paste the code and replace “xx” with the category ID (leave the minus sign in the code)
function exclude_category($query) {
if ( $query->is_home() ) {// set this to "is_archive()" to remove from blog
$query->set( 'cat', '-xx' );
}
return $query;
@Farmatique
Farmatique / gist:943977ed67891309016c579b3dc90edf
Created July 24, 2019 18:33
Pardot cut "Select" from the first option inside <select>
setTimeout(function(){
var theElements = document.querySelectorAll("#pardot-form select"); // seach all dropdown elements with " #pardot-forms select "
for(var i=0; i<theElements.length; i++) {
var str = theElements[i].children[0].innerHTML;
var res = str.match(/^Select\b (...+).../i);
theElements[i].children[0].innerHTML = '';
theElements[i].children[0].innerHTML = res[1];
}
@Farmatique
Farmatique / gist:3581d41d5e82b238ed6072254b55f4a2
Last active July 18, 2019 10:28
smooth scroll to section jquery v.3
$('a[href*="#"]').on('click', function(e) {
e.preventDefault()
$('html, body').animate(
{
scrollTop: $($(this).attr('href')).offset().top,
},
500,
'linear'
)
})
@Farmatique
Farmatique / gist:09e678ebc358cdfb1b1fb00c85aea7b4
Created July 17, 2019 15:32
add google font to wordpress
function add_google_fonts() {
wp_enqueue_style( ' add_google_fonts ', 'https://fonts.googleapis.com/css?family=Montserrat:300,400,500,600,700&display=swap', false );
}
add_action( 'wp_enqueue_scripts', 'add_google_fonts' );
wget -r -k -l 7 -p -E -nc -erobots=off --user-agent="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/5З7.З6 (KHTML, like Gecko) Chrome/60.0.З112.11З Safari/5З7.36" www.lica-center.com.ua
-- or if "502 bad gateway" you could try remove user-agent --