Skip to content

Instantly share code, notes, and snippets.

View joshuadavidnelson's full-sized avatar

Joshua Nelson joshuadavidnelson

View GitHub Profile
@joshuadavidnelson
joshuadavidnelson / duplicate-child-term-url-structure.php
Last active April 18, 2024 21:50
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 / obfuscate-email.php
Last active April 17, 2024 08:34
Obfuscate an email address output with PHP and CSS
<?php
/**
* Obfuscate an email address php output with some CSS help
*
* @author Joshua David Nelson, josh@joshuadnelson.com
* Based on:
* @link http://perishablepress.com/best-method-for-email-obfuscation/
*/
// PHP Output - replace the $instance['email'] with whatever input/variable is storing your clean email address
<?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 / example-output.html
Last active January 22, 2024 12:42
Using WordPress responsive images for css background-image property, in-line styling
<style>
.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-300x151.png)
}
@media only screen and (min-width: 300px) {.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-768x386.png)
}}
@media only screen and (min-width: 768px) {.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-1024x515.png)
}}
@joshuadavidnelson
joshuadavidnelson / create-image-id.php
Last active November 7, 2023 05:04
Programmatically create the image attachment and return the new media upload id.
<?php
/**
* Create the image attachment and return the new media upload id.
*
* @author Joshua David Nelson, josh@joshuadnelson.com
*
* @since 03.29.2017 updated to a class, utilizing code from Takuro Hishikawa's gist linked below.
*
* @see https://gist.github.com/hissy/7352933
*
@joshuadavidnelson
joshuadavidnelson / remove-default-taxonomies.php
Created November 13, 2013 04:41
Remove category and tag taxonomies. Useful if you're not using the blog functionality of WordPress, including the taxonomies. Be sure to uncomment the other line if you're using Genesis to avoid errors.
<?php
/**
*
* Remove default taxonomies
*
* @link http://w4dev.com/wp/remove-taxonomy/
*
*/
add_action( 'init', 'unregister_taxonomy');
@joshuadavidnelson
joshuadavidnelson / get-responsive-image.php
Last active August 7, 2023 13:16
Generate a img tag for responsive images in WordPress
<?php
/**
* Get the responsive image.
*
* @param string $image_id
* @param string $image_size optional
*
* @return string $output
*/
function get_responsive_image( $image_id, $size = 'medium' ) {
@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 / wordpress-debug-logger.php
Created January 31, 2015 16:17
Log errors in WordPress
<?php
/**
* Log any errors for debugging.
*
* @global WP_DEBUG
* @uses error_log
* @var string|array $message the error message (a string or array)
*/
if( !function_exists( 'jdn_log_me' ) ) {
function jdn_log_me( $message ) {
@joshuadavidnelson
joshuadavidnelson / custom-field-shortcode.php
Last active April 5, 2023 21:06
Add shortcode support to custom field output
<?php
/**
* Apply shortcodes to custom field output
*
* @author Joshua David Nelson, josh@joshuadnelson.com
*/
$custom_field_output = 'some text with a [shortcode]';
add_filter( 'custom_field', 'do_shortcode' );
$custom_field_output = apply_filters( 'custom_field', $custom_field_output );