Skip to content

Instantly share code, notes, and snippets.

View TeemuSuoranta's full-sized avatar
🐢
I may respond slowly, but I'll respond eventually. Probably.

Teemu Suoranta TeemuSuoranta

🐢
I may respond slowly, but I'll respond eventually. Probably.
View GitHub Profile
@TeemuSuoranta
TeemuSuoranta / fix-acf-menu-fields-to-polylang.php
Created March 11, 2021 13:51
Fix ACF menu location rules to work on all Polylang locales
<?php
/**
* Fix ACF menu location rules to work on all Polylang locales
*
* Polylang registers localized variations to menu locations and by default
* ACF cannot hook to all of them unless they are manually all picked.
* Polylang separates location with three undescores (eaxmple: primary___en).
*
* This hook automatically applies all menu location rules to all languages.
* Works for both nav_menu and nav_menu_item related fields.
@TeemuSuoranta
TeemuSuoranta / eml-to-filebird.sh
Created December 31, 2019 08:41
Migrate from Enhanced Media Library to Filebird
wp plugin deactivate enhanced-media-library
wp plugin activate filebird
wp search-replace 'media_category' 'nt_wmc_folder'
for term_id in $(wp term list nt_wmc_folder --field=term_id)
do
wp term meta set $term_id folder_type default
wp term meta set $term_id folder_position 0
@TeemuSuoranta
TeemuSuoranta / gist:16accb52a24f1f4dd0d22df701047d76
Created October 18, 2019 06:57
Remove empty paragraphs from post_content
<?php
/**
* Remove empty paragraphs
*
* @param string $content the HTML markup of content
*
* @return string the HTML markup of content
*/
add_filter('the_content', function ($content) {
/**
* Redirect .html URLs that cause 404
*/
add_action('template_redirect', function() {
if (is_404()) {
// get url without GET parameters
$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
/**
* Add support for correct UTF8 orderby for post_title (äöå)
*
* @param string $orderby ordering clause for query
*
* @return string ordering clause for query
*/
add_filter('posts_orderby', function($orderby) use ($wpdb) {
if(strstr($orderby, 'post_title')) {
@TeemuSuoranta
TeemuSuoranta / kunnat.php
Created March 8, 2017 14:55
Suomen kunnat maakunnittain 2017
<?php
$municipalities_by_region = array(
'Ahvenanmaa' => array(
35 => 'Brändö',
43 => 'Eckerö',
60 => 'Finström',
62 => 'Föglö',
65 => 'Geta',