Skip to content

Instantly share code, notes, and snippets.

@ramseyp
ramseyp / hide-editor.php
Created November 12, 2012 15:48
Hide the content editor for certain pages in WordPress
<?php
/**
* Hide editor on specific pages.
*
*/
add_action( 'admin_init', 'hide_editor' );
function hide_editor() {
// Get the Post ID.
@ramseyp
ramseyp / custom_comments.php
Last active August 17, 2023 07:36
Different ways of customizing the WordPress comment form
<?php
// Customized the comment form fields ( not the comment text area )
add_filter('comment_form_default_fields', 'my_comment_form_args');
// Customizes the text area - you have to do this here, rather than in comment_form_default_fields
add_filter('comment_form_field_comment', 'my_comment_form_field_comment');
// Customized the comment notes above the form fields
add_filter( 'comment_form_defaults', 'my_comment_form_defaults' );
@ramseyp
ramseyp / character-cleanup.sql
Created July 5, 2012 17:00
Clean up malformed characters in WordPress database
## Run this in phpMyadmin
##
## Cleans up Posts table
UPDATE wp_posts SET post_content = REPLACE(post_content, '“', '“');
UPDATE wp_posts SET post_content = REPLACE(post_content, '”', '”');
UPDATE wp_posts SET post_content = REPLACE(post_content, '’', '’');
UPDATE wp_posts SET post_content = REPLACE(post_content, '‘', '‘');
UPDATE wp_posts SET post_content = REPLACE(post_content, '—', '–');
UPDATE wp_posts SET post_content = REPLACE(post_content, '–', '—');
UPDATE wp_posts SET post_content = REPLACE(post_content, '•', '-');
@ramseyp
ramseyp / wp_user-profile-fields.php
Created January 31, 2012 19:45
Add Extra Fields to WordPress user profile
<?php
/* Add Extra Profile Meta fields to WordPress user profile
*/
//Extra Author Profile Meta
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<h3>Is this an active author?</h3>
@ramseyp
ramseyp / last-word.js
Created February 21, 2013 15:13
Select the last word in an element & wrap it with a span tag
jQuery(document).ready(function($){
$('h2.title').html(function(){
// separate the text by spaces
var text= $(this).text().split(' ');
// drop the last word and store it in a variable
var last = text.pop();
// join the text back and if it has more than 1 word add the span tag
// to the last word
return text.join(" ") + (text.length > 0 ? ' <span class="last">'+last+'</span>' : last);
@ramseyp
ramseyp / naked-css-wp.php
Last active April 9, 2020 15:31
WP snippets for CSS Naked Day
<?php
function bk_is_naked_day($d) {
$start = date('U', mktime(-12, 0, 0, 04, $d, date('Y')));
$end = date('U', mktime(36, 0, 0, 04, $d, date('Y')));
$z = date('Z') * -1;
$now = time() + $z;
if ( $now >= $start && $now <= $end ) {
return true;
}
@ramseyp
ramseyp / exc_format_query.php
Created June 7, 2012 05:27
Exclude a post format from the main query in WordPRess
<?php
/**
* Add a taxonomy query to pre_get_posts to remove Quote post formats from the main query
*
* @author Pat Ramsey
* @link http://slash25.com
*
* @param array tax_query $args
* @return modified $query
*/
@ramseyp
ramseyp / filter_yoast_seo.php
Created October 10, 2013 15:11
Filter Yoast Meta Box Priority - returning low moves it below standard meta boxes
<?php
// Filter Yoast Meta Priority
function move_yoast_seo_box() {
if ( defined( 'WPSEO_VERSION' ) ) :
add_filter( 'wpseo_metabox_prio', function() { return 'low'; } );
endif;
}
add_action('admin_init', 'move_yoast_seo_box');
@ramseyp
ramseyp / filter-shared-data.php
Created February 12, 2019 22:09
filter shared counts data
function shared_counts_flipboard_data_properties( $attr, $link ) {
if ( 'flipboard' === $link['type'] ) {
$attr['flip-widget'] = 'shareflip';
}
return $attr;
}
add_filter( 'shared_counts_link_data', 'shared_counts_flipboard_data_properties', 5, 2 );
@ramseyp
ramseyp / inf-soft-form-placeholder.js
Created October 3, 2012 16:03
Javascript used to make Infusionsoft form labels act as placeholders
// CSS for this can be found here: https://gist.github.com/3827867
jQuery(document).ready(function($){
// Add classes to the labels of selects, text-inputs, email inputs and textareas
$('.infusion-form .infusion-field select').prev('label').addClass('label-select');
$('.infusion-form .infusion-field input[type="email"], .infusion-form .infusion-field input[type="text"], .infusion-form .infusion-field textarea').prev('label').addClass('label-placeholder');
$('.infusion-form .infusion-field input[type="email"], .infusion-form .infusion-field input[type="text"], .infusion-form .infusion-field textarea').focus(function(){
$(this).prev('.infusion-field .label-placeholder').hide();