Skip to content

Instantly share code, notes, and snippets.

View mattradford's full-sized avatar
👋

Matt Radford mattradford

👋
View GitHub Profile
@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_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 / 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 / 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');
<?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 February 10, 2021 19:43
WordPress theme build and deploy
name: WordPress Build & Deploy Theme
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
@mattradford
mattradford / yoast_social_accounts.php
Last active June 20, 2019 20:45
Output Yoast Social links
/**
* 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 October 23, 2018 10:21 — forked from hanigamal/wp-install.sh
WordPress Commandline Local Install
#!/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