Skip to content

Instantly share code, notes, and snippets.

Avatar
👋

Matt Radford mattradford

👋
View GitHub Profile
@mattradford
mattradford / generatepress_polylang_404.php
Last active Jun 19, 2022
Translate the GeneratePress 404 page title using Polylang strings translation
View generatepress_polylang_404.php
/**
* 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_switcher.php
Last active Jun 19, 2022
Add Polylang language switcher to GeneratePress navigation
View generatepress_polylang_switcher.php
/**
* 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 / generatepress_polylang_logo.php
Last active Jun 19, 2022
Set GeneratePress logos based on Polylang current language
View generatepress_polylang_logo.php
/**
* 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 / mattrad-nav-menu-usage.php
Created Nov 19, 2021
WordPress nav menu with a title
View mattrad-nav-menu-usage.php
$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 Nov 12, 2021
Yoast Primary and Secondary Terms
View yoast-primary-and-secondary.php
<?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 Nov 10, 2021
Promote WordPress Categories to a top-level menu item
View promoteCategories.php
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');
View pewc_get_multicurrency_price.php
<?php
function pewc_get_multicurrency_price( $price ) {
// Compatibility with WooCommerce multilingual
$price = apply_filters( 'wcml_raw_price_amount', $price );
if( class_exists('WOOCS') ) {
global $WOOCS;
if ($WOOCS->is_multiple_allowed) {
$price = $WOOCS->woocs_exchange_value( floatval( $price ) );
@mattradford
mattradford / wordpress-theme-build-deploy.yml
Created Feb 10, 2021
WordPress theme build and deploy
View wordpress-theme-build-deploy.yml
name: WordPress Build & Deploy Theme
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
@mattradford
mattradford / yoast_social_accounts.php
Last active Jun 20, 2019
Output Yoast Social links
View yoast_social_accounts.php
/**
* Return a nav element populated with Yoast social accounts
*/
function yoast_social_accounts()
{
if ($social_accounts = get_option('wpseo_social')) {
$fb_url = $social_accounts['facebook_site'];
$twitter_account = $social_accounts['twitter_site'];
$youtube_url = $social_accounts['youtube_url'];
@mattradford
mattradford / wp-install.sh
Last active Oct 23, 2018 — forked from hanigamal/wp-install.sh
WordPress Commandline Local Install
View wp-install.sh
#!/bin/bash
#
# WP Commandline Local Install, by Brian Richards (@rzen)
#
# Creates a new directory, downloads WordPress, creates a database, sets up wp-config,
# optionally empties wp-content, and deletes other misc files. This compliments my local
# dev setup, outlined here: http://rzen.net/development/local-develoment-in-osx/
#
# Credit:
# Based on WPBuildr (https://github.com/AaronHolbrook/wpbuildr/). Props to Aaron Holbrook