Skip to content

Instantly share code, notes, and snippets.

@yunusga
yunusga / gist:33cf0ba9e311e12df4046722e93d4123
Created April 5, 2017 11:55
Debug WordPress 404 issues (permalinks, rewrite rules, etc.)
/* Produces a dump on the state of WordPress when a not found error occurs */
/* useful when debugging permalink issues, rewrite rule trouble, place inside functions.php */
ini_set( 'error_reporting', -1 );
ini_set( 'display_errors', 'On' );
echo '<pre>';
add_action( 'parse_request', 'debug_404_rewrite_dump' );
function debug_404_rewrite_dump( &$wp ) {
@mgratch
mgratch / add-noindex-to-posts.php
Created May 18, 2023 17:43
Use WP-CLI to enter `wp shell`, enter the following class, and then run `(new SEO_Update_Command())->__invoke()` to start the process.
if (class_exists('WP_CLI')) { class SEO_Update_Command { public function __invoke() { global $wpdb; $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'salary_market_data' AND post_parent != 0"); $progress = \WP_CLI\Utils\make_progress_bar( 'Updating...', count($post_ids)); foreach($post_ids as $post_id) { update_post_meta($post_id, "_yoast_wpseo_meta-robots-noindex", 1); $progress->tick(); } $progress->finish(); WP_CLI::success('Meta values updated successfully.'); }} WP_CLI::add_command('seo_update', 'SEO_Update_Command');}
@calliaweb
calliaweb / modify-tinymce-editor-to-remove-h1.php
Last active August 3, 2023 16:00
Modify TinyMCE editor to remove H1
<?php
// Do NOT include the opening php tag above
add_filter('tiny_mce_before_init', 'tiny_mce_remove_unused_formats' );
/*
* Modify TinyMCE editor to remove H1.
*/
function tiny_mce_remove_unused_formats($init) {
// Add block format elements you want to show in dropdown
$init['block_formats'] = 'Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6;Address=address;Pre=pre';
@logoscreative
logoscreative / plugin.php
Last active February 1, 2023 12:14
Friendlier, Safer WordPress Admin Areas
<?php
/**
* "Friendlier, Safer WordPress Admin Areas"
* Presented by Cliff Seal at WordCamp Atlanta 2015 and Asheville 2016
* Slides: http://www.slideshare.net/cliffseal/wp-admin
*
* Plugin Name: A Better Admin Experience
* Plugin URI: http://evermoresites.com
* Description: Cleans up and sanitizes the WordPress admin area
* Version: 1.0
/* PHP/Mark-up used to add the modal to the template */
add_action( 'wp_footer', array( $this, 'email_form_overlay' ), 1 );
function email_form_overlay() {
?>
<div class="modal" aria-describedby='modal-description' aria-hidden="true">
<div class="modal-overlay js-modal-overlay"></div>
<div class="modal-canvas">
<?php gravity_form( 1, false, true, false, array(), true); ?>
<div class="icon-close js-modal-close"></div>
@thomasgriffin
thomasgriffin / gist:4159035
Last active December 30, 2019 18:27
Add custom post types to search results in WordPress.
<?php
add_filter( 'pre_get_posts', 'tgm_io_cpt_search' );
/**
* This function modifies the main WordPress query to include an array of
* post types instead of the default 'post' post type.
*
* @param object $query The original query.
* @return object $query The amended query.
*/
function tgm_io_cpt_search( $query ) {
@jcasabona
jcasabona / howibuit.md
Last active September 4, 2019 13:40
Guest Notes for How I Built It Podcast

Guest Notes for How I Built It Podcast

Tips for Good Recording

I'll be doing dual track recording, but if you could record audio on your side that would be great! That way if we see a dip in connection or get weird quality, I can do some track-layering action. To do that:

On a Mac

screenshot 2016-07-29 14 05 25

@daronspence
daronspence / count-podcasts.php
Last active December 12, 2016 16:16
Podcast Count Shortcode
<?php
/**
* Plugin Name: Podcast Shortcode
* Description: Adds a shortcode to display your podcast count. <code>[podcast-count]</code>
* Version: 1.0
* Author: Daron Spence
* Author URI: https://daronspence.com/
*
* A simple shortcode to display the number of published podcasts on your site. Uses the `podcast` post type.
*
@bradpotter
bradpotter / responsive-menu.js
Last active January 4, 2016 11:09
Combine Primary and Secondary Menu into one Responsive Menu
/* Make sure your Menus are named Primary Navigation and Secondary Navigation in Appearance > Menus */
(function( window, $, undefined ) {
'use strict';
$('.nav-primary').before('<button class="menu-toggle" role="button" aria-pressed="false"></button>'); // Add toggles to menus
$('nav .sub-menu').before('<button class="sub-menu-toggle" role="button" aria-pressed="false"></button>'); // Add toggles to sub menus
// Show/hide the navigation
$('.menu-toggle, .sub-menu-toggle').click(function() {
@robneu
robneu / genesis-seo-post-info.php
Last active January 4, 2016 05:09
The default Genesis post info can be tweaked for a bit of extra SEO goodness. This will change your posts publish date to use the last-updated date instead. It also allows you to select a custom author page rather than using the standard post archive. This part is optional and doesn't affect the post date at all.
<?php
/**
* Some tweaks to the Genesis post info for SEO purposes.
*
* This set of functions are designed to change the output of the Genesis post info
* to reflect the date a post was updated rather than the date it was published. A
* function to set a custom author page is also included and is entirely optional.
*
* @author FAT Media, LLC
* @link http://auditwp.com/genesis-post-info-seo/