Skip to content

Instantly share code, notes, and snippets.

View landbryo's full-sized avatar
🤠
Always Excitied

Landon Otis landbryo

🤠
Always Excitied
View GitHub Profile
@landbryo
landbryo / del-tax-terms
Last active June 1, 2018 20:30
Use this function to quickly delete all taxonomy terms in chosen taxonomy. Replace tax-slug with your taxonomy's slug and load any page while logged in as an admin.
//////////////////////////////////
// DELETE ALL TERMS IN TAXONOMY //
//////////////////////////////////
function landbryo_delete_terms() {
if ( is_admin() ) {
$tax = 'tax-slug';
$terms = get_terms( $tax, array( 'fields' => 'ids', 'hide_empty' => false ) );
foreach ( $terms as $value ) {
wp_delete_term( $value, $tax );
@landbryo
landbryo / enfold-theme-options-title
Created June 1, 2018 18:21
If you're using the Enfold WordPress theme you can use this function to customize the theme options title.
/////////////////////////////////////
// CHANGE THEME OPTIONS MENU TITLE //
/////////////////////////////////////
add_filter('avia_filter_backend_page_title', 'change_theme_title');
function change_theme_title() {
return 'Theme Options';
}
@landbryo
landbryo / rem_enfold_backlink
Last active September 10, 2018 18:13
Removes WordPress Enfold theme backlink without having to modify the footer.php file.
@landbryo
landbryo / custom_query_order
Created June 1, 2018 18:14
This WordPress filter and function can be used to sort posts by the second word in the title.
/////////////////////////
// CUSTOM QUERY FILTER //
/////////////////////////
function orderby_lastname($orderby_statement) {
$orderby_statement = "RIGHT(post_title, LOCATE(' ', REVERSE(post_title)) - 1) ASC";
return $orderby_statement;
}
// add filter with function before args
@landbryo
landbryo / dis_plugin_update
Created June 1, 2018 17:43
This disables the notification letting you know how many plugins updates are available in WordPress. This is great when combined with a custom user role, but probably not a good idea to use this globally.
//////////////////////////////////
// DIABLE PLUGIN UPDATE COUNTER //
//////////////////////////////////
add_filter('site_transient_update_plugins', '__return_false');
@landbryo
landbryo / enfold_child_script
Last active June 4, 2018 20:42
If you are using the Enfold WordPress theme, it is likely that you'll need to make modifications to its main script avia.js. This is how you can safely copy the avia.js file to your child theme and make modifications.
/* enqueue child script if not in dashboard */
if (!(is_admin())) {
function change_aviajs() {
wp_enqueue_script( 'avia-default-child', get_stylesheet_directory_uri().'/js/avia.js', array('jquery'), 2, true );
}
add_action( 'wp_print_scripts', 'change_aviajs', 100 );
}
/* dequeue child script */
@landbryo
landbryo / defer-scripts
Last active June 1, 2018 17:46
WordPress function to defer jQuery parsing using the HTML5 defer property. Helpful resource: https://developer.wordpress.org/reference/hooks/clean_url/
//////////////////
// DEFER JQUERY //
//////////////////
if (!(is_admin())) {
function defer_parsing($url) {
if (FALSE === strpos($url, '.js')) return $url;
if (strpos($url, 'jquery.js')) return $url;
return "$url' defer onload='";
@landbryo
landbryo / wp_change_img_editor
Last active May 24, 2018 19:20
Use this function or something similar to change the image editor it is using. This will often fix media library image upload problems. Helpful resources: https://developer.wordpress.org/reference/hooks/wp_image_editors/ https://developer.wordpress.
///////////////////////
// CHANGE IMG EDITOR //
///////////////////////
function landbryo_img_edit($array) {
return array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
}
add_filter( 'wp_image_editors', 'landbryo_img_edit' );
jQuery('img').removeAttr('title');
@landbryo
landbryo / git-commands
Last active May 23, 2018 15:06
Git commands I've come to find useful and want to find in one place.
git clone https:// // clone repository
git add -A // stages all
git add . // stages new and modified, without deleted
git add -u // stages modified and deleted, without new
git commit -m "add message here" //commit changes with a message
git push origin master //push changes to master branch
git reset --hard
git pull