Skip to content

Instantly share code, notes, and snippets.

View joshuadavidnelson's full-sized avatar

Joshua Nelson joshuadavidnelson

View GitHub Profile
@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.
View multilingualpress-cross-post-type.php
<?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.
View dwpb-example-filter-author-archive-post-types.php
<?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.
View multilingualpress-filter-draft-hreflangs.php
<?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.
View stf-jquery-header-in-archives-only.php
<?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.
View add-yoast-redirect.php
<?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
View remove-genesis-layout-settings-from-customizer.php
<?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
View grid-block.scss
.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
View change-wp-user-password.sql
UPDATE wp_users
SET user_pass = MD5('newpassword')
WHERE ID = 55;
View scripts-to-footer-example.php
@joshuadavidnelson
joshuadavidnelson / custom-route-notification-multiple-fields.php
Last active December 8, 2017 20:04
Per emailed question, utilizing the example in my blog post "User Dropdown List & Custom Notification Routing in Gravity Forms" for multiple fields that have the custom 'user-emails' CSS class to email multiple people
View custom-route-notification-multiple-fields.php
<?php
/**
* Change the sent to email address in the notification
*
* @author Joshua David Nelson, josh@joshuadnelson.com
**/
// Route to user address from drop down list, update the '1' to the ID of your form
add_filter( 'gform_notification_1', 'route_user_email_notification', 10, 3 );
function route_user_email_notification( $notification, $form , $entry ) {