Skip to content

Instantly share code, notes, and snippets.

View timothyjensen's full-sized avatar

Tim Jensen timothyjensen

View GitHub Profile
<?php
add_filter( 'enter_title_here', function( $title ) {
$screen = get_current_screen();
if ( 'your_custom_post_type' == $screen->post_type ){
$title = 'Your custom placeholder text';
}
return $title;
@timothyjensen
timothyjensen / cpt-registration.php
Last active June 4, 2019 19:22
Change the placeholder text for the post title field.
<?php
// Add 'title_placeholder' to the array of arguments when registering the custom post type.
$cpt_args = array(
'title_placeholder' => 'Team member name',
);
register_post_type( 'team_members', $cpt_args );
@timothyjensen
timothyjensen / acf-local-json.php
Last active June 4, 2018 11:12
Use ACF local JSON file for get_all_custom_field_meta().
<?php
// Replace with the name of your field group JSON.
$field_group_json = 'group_59e226a200966.json';
$field_group_array = json_decode( file_get_contents( get_stylesheet_directory() . "/acf-json/{$field_group_json}" ), true );
// Omit this line when using the Field Group Values package/plugin.
$config = $field_group_array['fields'];
@timothyjensen
timothyjensen / searchform.php
Created October 13, 2017 11:18
Modify the standard WordPress search form to perform faceted search.
<?php
add_filter( 'get_search_form', 'prefix_render_faceted_search_form' );
/**
* Adds checkboxes to the search form for searching specific post types.
*
* @param string $form The search form HTML output.
*
* @return string
*/
function prefix_render_faceted_search_form( $form ) {
@timothyjensen
timothyjensen / jquery.js
Last active November 3, 2020 10:01
Wrap sibling groups using jQuery.
$(document).ready(function() {
$(':not(.sibling-element) + .sibling-element, * > .sibling-element:first-of-type').
each(function() {
$(this).
nextUntil(':not(.sibling-element)').
addBack().
wrapAll('<div class="sibling-wrapper" />');
});
});
@timothyjensen
timothyjensen / functions.php
Last active June 20, 2017 15:40
$wpdb->prepare for SQL IN statements
<?php
$data_types = [ 'data_item_one', 'data_item_two' ];
// Props to @hellofromtonya for this.
$data_type_placeholders = implode( ', ', array_fill( 0, count( $data_types ), '%s' ) );
global $wpdb;
$query = "
SELECT pm.post_id, pm.meta_key, pm.meta_value
@timothyjensen
timothyjensen / functions.php
Last active June 4, 2019 19:22
Change the default Genesis read more link
<?php
add_filter( 'get_the_content_more_link', 'prefix_change_more_link_text' );
/**
* Replaces the default Genesis [Read More...] with Read More.
*
* @param string $more_link The content more link.
*
* @return string
*/
function prefix_change_more_link_text( $more_link ) {
@timothyjensen
timothyjensen / contact.html
Created April 23, 2017 19:39 — forked from atcraigwatson/contact.html
Bootstrap Ajax Contact Form
<form id="contact-form" method="post" action="mailer.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_name">Firstname *</label>
@timothyjensen
timothyjensen / functions.php
Created April 12, 2017 16:41
CMB2 on Genesis Archive Settings.
<?php
add_action( 'cmb2_admin_init', 'yourprefix_register_demo_metabox' );
/**
* Creating a metabox for a Genesis CPT Archive Settings page, where the CPT is 'webinars'.
*/
function yourprefix_register_demo_metabox() {
/**
* Sample metabox to demonstrate each field type included
@timothyjensen
timothyjensen / outside-structural-wrap.php
Last active March 24, 2017 22:20 — forked from hellofromtonya/before-structural-wrap.php
Insert HTML before or after the Genesis structural wrap for the given contextual area.
<?php
add_action( 'genesis_meta', 'process_structural_wrap_handler' );
/**
* Process the structural wrap handler.
*
* @since 1.0.0
*
* @return void
*/
function process_structural_wrap_handler() {