Skip to content

Instantly share code, notes, and snippets.

View joshuadavidnelson's full-sized avatar

Joshua Nelson joshuadavidnelson

View GitHub Profile
<?php
/**
* Filter the post search arguments allow for cross-post-type connections in MultilingualPress.
*
* MultilingualPress (MLP) connects translated posts and pages, but by default doesn't connection across post types.
* This changes that behavior by allowing other post types to be chosen in the interface. No other modifications are
* needed to achieve this, because MLP uses the post_id and doesn't care about post_type outside of the search query.
*
* @param array $args the WP_Term_Query arguments used.
* @return array
@joshuadavidnelson
joshuadavidnelson / duplicate-child-term-url-structure.php
Last active April 19, 2024 06:06
Using a Parent > Child category structure with duplicate child url slugs; for urls like `category/parent-1/child` and `category/parent-2/child`.
<?php
/**
* Plugin Name: Duplicated Child Term Url Slugs
* Description: Duplicate child term urls slugs in hierarchical taxonomies.
* Version: 0.1.0
* Author: joshuadnelson
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
* This is setup like a plugin, but can be included in a theme or as a class in a plugin.
@joshuadavidnelson
joshuadavidnelson / multilingualpress-cross-post-type.php
Last active August 9, 2022 19:23
Filter the MultilingualPess admin metabox to allow for connecting translations to other post types on remote site.
<?php
/**
* Filter the post search arguments allow for cross-post-type connections.
*
* @param array $args the WP_Query arguments used.
* @return array
*/
function remote_post_search_arguments( $args ) {
$translated_post_types = array( 'post', 'page', 'product' );
@joshuadavidnelson
joshuadavidnelson / dwpb-example-filter-author-archive-post-types.php
Created April 24, 2022 14:43
Disable Blog Example: Add new post types to author archives. By default only posts are shown on author archives, if other post types are to appear on the author archives, pass them with this filter.
<?php
add_filter( 'dwpb_author_archive_post_types', 'dwpb_example_filter_author_archive_post_types', 10, 1 );
/**
* Example: Filter `dwpb_author_archive_post_types` for Disable Blog plugin.
*
* Add new post types to author archives.
*
* By default only posts are shown on author archives, if other post types are to appear
* on the author archives, pass them with this filter.
*
@joshuadavidnelson
joshuadavidnelson / multilingualpress-filter-draft-hreflangs.php
Created March 30, 2022 21:00
Filter the hreflang urls and remove any that are indicative of draft or otherwise non-published content. Assumes that linked translations that are not yet published will show up as /?p=123 instead of pretty permalink.
<?php
/**
* Filter the hreflang urls and remove any that are indicative of draft or otherwise non-published content.
*
* Linked translations that are not yet published will show up as /?p=123 instead of pretty permalink.
*
* @param array $urls the array of language => url hreflang urls.
* @return array
*/
add_filter( 'multilingualpress.hreflang_translations', 'filter_mlp_hreflang_translations' );
@joshuadavidnelson
joshuadavidnelson / stf-jquery-header-in-archives-only.php
Last active July 2, 2021 16:26
Place jQuery in the head on archive pages. You can use other conditionals in place of `is_archive()` to achieve this behavior for other conditions.
<?php
/**
* Use this filter to force jquery to remain in the head section of the page on archives.
*
* @see https://wordpress.org/support/topic/exclude-jquery-for-other-archive-pages/
* @date 2021-07-02
*/
add_filter( 'stf_jquery_header', 'jdn_archive_header_scripts', 10 );
function jdn_archive_header_scripts( $bool ) {
@joshuadavidnelson
joshuadavidnelson / add-yoast-redirect.php
Last active June 10, 2023 04:47
Programmatically add a redirect to the Yoast SEO Premium redirects.
<?php
/**
* Create a new redirect within the Yoast redirect system.
*
* @param string $origin_url redirecting from.
* @param string $destination_url redirecting to.
* @param int $type redirect code, defaults to 301.
* @param string $format the format, either 'plain' or 'regex', defaults to 'plain'.
* @return void
*/
@joshuadavidnelson
joshuadavidnelson / remove-genesis-layout-settings-from-customizer.php
Created January 1, 2020 20:11
Remove the Genesis Layout settings in Customizer
<?php
// Remove layout settings from customizer
add_filter( 'genesis_customizer_theme_settings_config', 'jdn_filter_genesis_customizer_theme_settings' );
function jdn_filter_genesis_customizer_theme_settings( $config ) {
if( isset( $config['genesis']['sections']['genesis_layout'] ) )
unset( $config['genesis']['sections']['genesis_layout'] );
return $config;
@joshuadavidnelson
joshuadavidnelson / grid-block.scss
Created July 31, 2019 04:11
css grid example with modernizr assisted fallback
.grid-block {
float: left;
}
.grid {
$grid-gap: 9px;
// Columns!
@media screen and ( min-width: 600px ) { // responsive grid
display: grid;
@joshuadavidnelson
joshuadavidnelson / change-wp-user-password.sql
Created July 24, 2018 05:08
SQL for updating a user password in WordPress
UPDATE wp_users
SET user_pass = MD5('newpassword')
WHERE ID = 55;