Skip to content

Instantly share code, notes, and snippets.

View jonathan-dejong's full-sized avatar

Jonathan de Jong jonathan-dejong

View GitHub Profile
@jonathan-dejong
jonathan-dejong / wpseo-and-BTF
Last active May 9, 2019 07:39
Example of using WordPress SEO By Yoast filters with Beautiful Taxonomy Filters
<?php
/* This file is taken directly from a clients site so it contains strings and conditions not necessarily useful to anyone else.
However it does show how one can use these filters to modify the meta information for the different filtered results */
/* CHANGE META DESCRIPTION ON KLINIK FILTER PAGES */
add_filter('wpseo_metadesc', 'custom_metadesc', 10, 1);
function custom_metadesc($desc){
if(is_tax(array('omrade', 'yrkeskategori', 'specialisering', 'betalningsmedel', 'forsakringsbolag'))){
global $wp_query;
$termID = $wp_query->queried_object->term_id;
@jonathan-dejong
jonathan-dejong / api_template-part.php
Created March 10, 2015 09:19
Modify update_sub_field to allow for inserting numbered rows even when no rows exist yet
/* Change this
* ===============================
*/
// sub fields
foreach( $selector as $s ) {
if( is_numeric($s) ) {
$row_i = intval($s) - 1;
@jonathan-dejong
jonathan-dejong / composer.json
Created October 10, 2015 12:37 — forked from pelmered/composer.json
Example composer.json for WordPress
{
"repositories": [
{
"type": "composer",
"url": "http://wpackagist.org"
},
{
"type": "package",
"package": {
"name": "advanced-custom-fields/advanced-custom-fields-pro",
@jonathan-dejong
jonathan-dejong / load_translated_value_if_exists.php
Last active May 18, 2016 13:31
Automatically fetch current language meta value for user fields with ACF
/*
* Modify ACF fields to account for translations if available
*
* This solution requires the use of Polylang for WP translations.
* Use this by duplicating the field groups for user meta and append _languageslug to each field in the duplicated group.
* So for a site with a swedish translation an example field would be named "user_phonenumber"
* in english (default) and in the swedish translation group "user_phonenumber_sv"
*/
function load_translated_value_if_exists( $value, $post_id, $field ){
@jonathan-dejong
jonathan-dejong / Check if post has grandchildren.php
Created May 18, 2016 06:25
A simple helper function for WordPress to check wether a post has grandchildren. Takes 1 parameter of a post id. Returns boolean (true or false)
function has_grandchildren( $post_id ){
$children = get_children(array(
'post_parent' => $post_id
));
if( $children ){
foreach( $children as $child ){
$grandchildren = get_children(array(
'post_parent' => $child->ID
@jonathan-dejong
jonathan-dejong / mod-search-wp.php
Last active June 9, 2016 22:06
Modify search string
function ugly_search($query) {
if( is_search() ) {
$org_s = $query->query_vars["s"];
$query->set('s', $org_s . ' extra sträng');
}
}
add_action('pre_get_posts', 'ugly_search');
@jonathan-dejong
jonathan-dejong / changes-to-pickup-plus.php
Created June 21, 2016 12:27
Changes to pickup plus to include user in order note
// make a note of the change
$order->add_order_note(
sprintf( __( 'Pickup location changed to %s', 'woocommerce-shipping-local-pickup-plus' ),
$this->get_formatted_address_helper( $pickup_location, true )
), false, true
);
@jonathan-dejong
jonathan-dejong / readallfilesoftype.php
Created September 15, 2016 14:28
Read all files of specific file type
<?php
/**
* Reads all files of a specific file type in a folder and returns them as an array.
*
*/
public function read_files() {
$uploads_directory = trailingslashit( plugin_dir_path( dirname( __FILE__ ) ) ) . 'uploads/';
$files = array_values( array_filter( scandir( $dir ), function( $file ) {
return ( pathinfo( $file, PATHINFO_EXTENSION ) != 'txt' ? false : true );
} ) );
jQuery(document).bind('FBSDKLoaded', function() {
/*
* Trigger facebook share dialog
*/
jQuery('.facebook-share').click(function(){
var href = window.location.href;
FB.ui({
<?php
global $post;
if ( function_exists( 'acf_add_local_field_group' ) ) :
acf_add_local_field_group(array(
'key' => 'group_58bff7f25c321',
'title' => 'Garderobsbyggaren',
'fields' => array(),
'location' => array(
array(