Skip to content

Instantly share code, notes, and snippets.

@ramseyp
ramseyp / wp_user-profile-fields.php
Created Jan 31, 2012
Add Extra Fields to WordPress user profile
View wp_user-profile-fields.php
<?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 / custom_comments.php
Last active May 29, 2021
Different ways of customizing the WordPress comment form
View custom_comments.php
<?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 / hide-editor.php
Created Nov 12, 2012
Hide the content editor for certain pages in WordPress
View hide-editor.php
<?php
/**
* Hide editor on specific pages.
*
*/
add_action( 'admin_init', 'hide_editor' );
function hide_editor() {
// Get the Post ID.
@ramseyp
ramseyp / last-word.js
Created Feb 21, 2013
Select the last word in an element & wrap it with a span tag
View last-word.js
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 Apr 9, 2020
WP snippets for CSS Naked Day
View naked-css-wp.php
<?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 Jun 7, 2012
Exclude a post format from the main query in WordPRess
View exc_format_query.php
<?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 Oct 10, 2013
Filter Yoast Meta Box Priority - returning low moves it below standard meta boxes
View filter_yoast_seo.php
<?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 Feb 12, 2019
filter shared counts data
View filter-shared-data.php
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 Oct 3, 2012
Javascript used to make Infusionsoft form labels act as placeholders
View inf-soft-form-placeholder.js
// 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();
@ramseyp
ramseyp / page_template_column.php
Created Dec 11, 2012
Add a page template column to WordPress's Pages view.
View page_template_column.php
<?php
/**
*
* Add page template column to page listing. Make the Template column sortable
* http://www.codehooligans.com/2011/07/13/adding-custom-columns-to-wordpress-post-listing/
* http://justintadlock.com/archives/2011/06/27/custom-columns-for-custom-post-types/
*
*/