Skip to content

Instantly share code, notes, and snippets.

View mattradford's full-sized avatar
👋

Matt Radford mattradford

👋
View GitHub Profile
@mattradford
mattradford / licence activation.php
Last active October 28, 2023 19:25
ACF5 Pro licence activation. Could be adapted for any other plugin that requires a licence key, but doesn't yet support defining it in wp-config. Fires on theme activation.
// Place this in wp-config
define( 'ACF_5_KEY', 'yourkeyhere' );
// Set ACF 5 license key on theme activation. Stick in your functions.php or equivalent.
function auto_set_license_keys() {
if ( ! get_option( 'acf_pro_license' ) && defined( 'ACF_5_KEY' ) ) {
$save = array(
'key' => ACF_5_KEY,
@mattradford
mattradford / gradient_overlay.css
Created November 6, 2014 11:51
bg gradient overlay
// http://codepen.io/alexcarpenter/pen/LveDx
html, body {
width: 100%;
height: 100%;
}
.bg-img {
width: 100%;
height: 100%;
@mattradford
mattradford / acf_get_directions.php
Last active February 16, 2023 12:08
ACF Get Directions map link
<?php
$location = get_field('map_location');
if ( !empty( $location ) ) :
$map_url = 'https://www.google.com/maps/dir/?api=1&destination=' . $location['lat'] . ',' . $location['lng'];
echo '<a href=". esc_url( $map_url ) . '" rel="nooopener">Get directions</a>';
endif;
?>
<p>This should produce a link like this:</p>
<a href="https://www.google.com/maps/dir/?api=1&destination=51.072159,1.088130">Get directions</a>
@mattradford
mattradford / generatepress_polylang_404.php
Last active June 19, 2022 13:14
Translate the GeneratePress 404 page title using Polylang strings translation
/**
* Translate the GeneratePress 404 page title
*
* The string can be translated in Languages -> Strings translations
*/
if ( function_exists( 'pll_register_string' ) ) {
function mattrad_404_text() {
$error_text = 'That page cannot be found';
pll_register_string( '404', $error_text , 'text_domain');
return pll__( $error_text );
@mattradford
mattradford / generatepress_polylang_logo.php
Last active June 19, 2022 13:14
Set GeneratePress logos based on Polylang current language
/**
* Set GeneratePress site logo based on Polylang current language
*
* This example function allows for the default logo to be set by the English choice, and supports
* Polish, Dutch and German language-specific logos
*/
if ( ! function_exists( 'generate_construct_logo' ) || ! function_exists( 'pll_current_language' ) ) {
// Change logo depending on the language
// An improvemnt to this would be to not set the array of logos, but check for a logo/language match
function mattrad_default_logo( $url ) {
@mattradford
mattradford / generatepress_polylang_switcher.php
Last active June 19, 2022 13:11
Add Polylang language switcher to GeneratePress navigation
/**
* Add Polylang language switcher before GeneratePress navigation
*
* @link https://polylang.pro/doc/function-reference/
*/
if ( ! function_exists( 'generate_navigation_position' ) || ! function_exists( 'pll_the_languages' )) {
function mattrad_add_switcher() {
pll_the_languages([
'dropdown' => 1,
'hide_if_empty' => 1,
@mattradford
mattradford / facetwp_load_more_and_all.php
Last active February 3, 2022 23:17
FacetWP load more and load all
// Adapted from https://gist.github.com/mgibbs189/f2469009a7039159e229efe5a01dab23
function fwp_load_more() {
?>
<script>
(function($) {
$(function() {
if ('object' != typeof FWP) {
return;
}
@mattradford
mattradford / mattrad-nav-menu-usage.php
Created November 19, 2021 15:37
WordPress nav menu with a title
$menu_locations = get_nav_menu_locations();
// Pass this function a menu location
echo mattrad_nav_menu('footer_one', $menu_locations);
@mattradford
mattradford / yoast-primary-and-secondary.php
Last active November 12, 2021 17:36
Yoast Primary and Secondary Terms
<?php
/**
* Post Categories
*
* Get Primary term, if set, and other terms for a post (with Primary Term excluded)
*
* @category Theme
* @package MattRadford/mattradford
* @author Matt Radford <matt@mattrad.uk>
@mattradford
mattradford / promoteCategories.php
Created November 10, 2021 14:42
Promote WordPress Categories to a top-level menu item
add_action('admin_menu', [$this, 'promoteCategories']);
/**
* Promote Categories to a top-level menu item
*
* @return void
*/
public function promoteCategories()
{
remove_submenu_page('edit.php', 'edit-tags.php?taxonomy=category');