Skip to content

Instantly share code, notes, and snippets.

View rmpel's full-sized avatar

Remon Pel rmpel

View GitHub Profile
@rmpel
rmpel / seo-sitemap-with-wpml-content-url-fix.php
Last active February 12, 2020 07:24
Fix the output of the XML sitemap so they show the correct localised URLs. This is an add-on for when you change the URLs using other techniques, see README.
<?php
// supports Yoast SEO and Yoast SEO Premium
add_filter('wpseo_sitemap_entry', 'wpseo_sitemap_entry', 10, 3);
// Supports SEO by Rank Math
add_filter('rank_math/sitemap/entry', 'wpseo_sitemap_entry', 10, 3);
function wpseo_sitemap_entry ( $url, $type, $object ) {
global $sitepress;
@rmpel
rmpel / translate-custom-post-type-archive-slug.php
Last active October 30, 2023 08:39
Translate post-type-archive-slug when different from post-type-slug. WPML allows translating custom post-type slug, but not the custom post-type-archive slug
<?php
/**
* Translate post-type-archive-slug when different from post-type-slug.
*
* You can have your archive slug set to, for example /books and the singles on /book/title by setting
* $args['rewrite'] => [ 'slug' => 'book', ... ];
* $args['has_archive'] => 'books';
* when registering your post_type
*
@rmpel
rmpel / allow-username-change.php
Last active March 17, 2023 07:10
Allo WordPress administrators to update username
<?php
/**
* Hook in the 'errors' hook as this is just in time and allows us to return an error in case of conflict.
*
* @package rmpel/WordPress
* @subpackage rmpel/WordPress/AllowUsernameChange
*/
add_action(
'user_profile_update_errors',
@rmpel
rmpel / translated-page-for-posts-post-url-base.php
Last active February 12, 2020 07:25
Translated POSTS urls in WPML WordPress website with a "Page for Posts" as POST-URL-base
<?php
/**
* Notes on the following section
*
* Correct set-up is:
*
* Set your page-for-posts to a certain WordPress Posts, for example /nl/nieuws/
* Set your permalink structure to the same; /nieuws/%postname%/
*
@rmpel
rmpel / redirect-to-browser-language-wp-wpml.php
Last active December 18, 2019 13:52
Redirect to browser language in WordPress + WPML when the default language is in a subfolder (as the rest) and there is no real homepage.
<?php
// redirect to language if no language
add_action( 'after_setup_theme', function () {
if ( is_admin() ) {
// we are on admin; do nothing
return;
}
if ( $GLOBALS['pagenow'] === 'wp-login.php' ) {
@rmpel
rmpel / lbl.sh
Last active October 14, 2023 09:26
Local Lightning - The unofficial CLI for the new Local 5.x and 6.x version - this is work in progress.
#!/usr/bin/env bash
#########
## Configration:
## Set your primary and secondary development paths.
## YOU CANNOT HAVE SPACES IN THE PRIMARY PATH - If you have, then most tooling here will fail because of limitations in macOS Terminal.
## AND NO - This tool is not built to use a different terminal.
##
PRIMARY_LOCATION=~/Development
SECONDARY_LOCATION=/Volumes/Macintosh\ SD/Development
@rmpel
rmpel / README.md
Last active June 5, 2019 13:52
Symfony 4 cheatsheet

Symfony 4 cheatsheet

terms

  1. Entity - a thing to store in the database
  2. Repository - handles the entities
  3. Service - A tool or set of tools (like a Mailer or an API Library)
  4. Route - Links a URL to code
  5. Controller - The above code resides herein; routes that belong to eachother like lists for entities and CRUD for those entities are bundled in their own controller.
  6. View - How is the data presented to the user. This can be ANYTHING! HTML, XML, JSON, a File Download etc.
@rmpel
rmpel / gadwp-tweak-muplugin.php
Created April 26, 2019 07:31
Google Analytics Dashboard for WordPress (GADWP) plugin tweak to put TagManager on top of the HEAD.
<?php
/**
* THIS CODE MAKES ONE CRITICAL ASSUMPTION!
* You are actually using GADWP in TagManager mode.
*
* There is no check that TagManager is actively in use, if you disable TagManager,
* change the word 'init' to '_init' :)
*/
@rmpel
rmpel / mu-plugin-cf7-auto-balance-form-html.php
Created March 11, 2019 14:43
Auto-balance HTML for ContactForm 7
<?php
/**
* WHY? Because invalid HTML will break a page, will break visible form feedback.
* Still, WHY? Well, you are right, CF7 should do this all on their own.
*/
add_action( 'wpcf7_save_contact_form', function(WPCF7_ContactForm $contact_form) {
// this is an action, contact_form not given as pointer, so get the pointer from CF7;
$cf = WPCF7_ContactForm::get_current();
@rmpel
rmpel / mu-new-jquery.php
Last active October 7, 2019 10:09
The bestest way to change the jQuery version in WordPress
<?php
/**
* Attention all WordPress developers.
* NEVER EVER EVER DO THIS:
wp_deregister_script('jquery');
* AND I DO MEAN NEVER!!!!!
* Any plugin that has dependency on jQuery registered like
wp_register_script( 'a-script', .., .., deps: [ 'jquery ' ], ..);
* will now BREAK!!!!