Skip to content

Instantly share code, notes, and snippets.

/**
* Adds a meta box
*/
function simple_meta_box() {
add_meta_box( 'prfx_meta', ( 'View Post' ), 'simple_meta_box_callback', 'staff', 'side', 'high' );
}
add_action( 'add_meta_boxes', 'simple_meta_box' );
/**
* Outputs the content of the meta box
@philhoyt
philhoyt / fields-submit.html
Created December 16, 2016 00:19
Custom Ninja Forms Submit Button
<script id="tmpl-nf-field-submit" type="text/template">
<a id="nf-field-{{{ data.id }}}" class="btn {{{ data.renderClasses() }}} nf-element " target="_self" href="#">
<span class="btn-content">{{{ data.label }}}</span>
<span class="icon"><i class="fa fa-arrow-right" aria-hidden="true"></i></span>
</a>
</script>
@philhoyt
philhoyt / ninja_forms_field_template_file_paths.php
Last active December 16, 2016 02:01
Ninja Form Custom Field Template Path
add_filter( 'ninja_forms_field_template_file_paths', 'custom_field_file_path' );
function custom_field_file_path( $paths ){
$paths[] = get_stylesheet_directory() . '/ninja-forms/templates/';
return $paths;
}
@philhoyt
philhoyt / enqueue-google-fonts-wordpress.php
Last active July 2, 2018 23:54
Enqueue Google Fonts in WordPress
/**
* Register custom fonts.
*/
function themeslug_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/*
* Translators: If there are characters in your language that are not supported
@philhoyt
philhoyt / client-role-plugin.php
Created April 11, 2023 14:18
WordPress Client Role Plugin - Create a user role similar to Admin and revokes specific capabilities.
<?php
/**
* Plugin Name: Client Role Plugin
* Plugin URI: https://gist.github.com/philhoyt/54a4a4e5a48d8cb0beb20edf1ba1ae51
* Description: Adds a 'Client' user role and revokes certain capabilities from it.
* Version: 1.0.0
* Author: Your Name
* Author URI: https://philhoyt.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@philhoyt
philhoyt / exclude_empty_post_content.php
Last active May 5, 2023 15:56
Remove posts with empty content from WordPress Search Results
<?php
/**
* Exclude posts with empty post_content from search results
*/
function modify_search_query( $query ) {
// Check if this is a search query and not an admin query
if ( $query->is_search() && ! is_admin() ) {
// Add a filter to exclude posts with empty post_content
add_filter( 'posts_where', 'exclude_empty_post_content' );
@philhoyt
philhoyt / advanced-custom-fields-post-title.php
Last active November 11, 2023 00:51
Using Advanced Custom Fields to create your Post Title
<?php
/** Create Title and Slug */
function acf_title( $value, $post_id, $field ) {
if ( get_post_type( $post_id ) === 'staff' ) {
$new_title = get_field( 'first_name', $post_id ) . ' ' . $value;
$new_slug = sanitize_title( $new_title );
wp_update_post(
array(