Skip to content

Instantly share code, notes, and snippets.

View BicanMarianValeriu's full-sized avatar
💭
I may be slow to respond.

Vali BicanMarianValeriu

💭
I may be slow to respond.
View GitHub Profile
@BicanMarianValeriu
BicanMarianValeriu / Map-Variables-Over-String.js
Last active April 17, 2020 00:06
Fanciest Variable Mapping over a string
const variables = {
name: 'Bican Marian Valeriu',
job: 'WordPress Developer',
};
const destruct = (obj, ...keys) => keys.reduce((a, c) => ({ ...a, [c]: obj[c] }), {});
const mapVariables = (variables, string) => {
let rxp = /{{([^}]+)}}/g, curMatch;
/**
* Get primary taxonomy term (YoastSEO).
*
* @param mixed $taxonomy Taxonomy to check for.
* @param boolean $term_as_obj Whether to return an object or the term name.
* @param int $post_id Post ID.
* @return mixed The primary term.
*/
function get_primary_tax_term( $post_id = 0, $taxonomy = 'category', $term_as_obj = true ) {
if ( 0 === $post_id ) {