Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍👦
My son is my everything

Cameron Jones cameronjonesweb

👨‍👦
My son is my everything
View GitHub Profile
View acf-options.php
<?php
function cameronjonesweb_acf_setup() {
acf_add_options_page(
array(
'page_title' => 'Theme Settings',
'menu_slug' => 'cameronjonesweb-theme-settings',
)
);
acf_add_local_field_group(
array(
@cameronjonesweb
cameronjonesweb / functions.php
Created May 30, 2019
Preserve taxonomy heirarchy on edit post page
View functions.php
<?php
add_filter('wp_terms_checklist_args', function ($args){
$args['checked_ontop'] = false;
return $args;
});
@cameronjonesweb
cameronjonesweb / taxonomy-radio-buttons.php
Created Jul 20, 2019
Converts the category checkboxes to radio buttons
View taxonomy-radio-buttons.php
<?php
function cameronjonesweb_radio_taxonomy_meta_box( $post, $box ) {
ob_start();
post_categories_meta_box( $post, $box );
$meta_box = ob_get_clean();
echo str_replace( 'checkbox', 'radio', $meta_box );
}
@cameronjonesweb
cameronjonesweb / functions.php
Last active Oct 7, 2020
Helper function to generate post type labels
View functions.php
<?php
/**
* Generates the post type labels
*
* @param string $single Singular name of the post type.
* @param string $plural Plural name of the post type.
* @param array $overrides Override any generated labels.
* @return array The post type labels
*/
function cameronjonesweb_generate_post_type_labels( $single, $plural, $overrides = [] ) {
View cpt-rewrites.php
<?php
add_action( 'init', 'rewrites' );
add_filter( 'post_type_link', 'filter_post_link', 1, 2 );
function rewrites() {
add_rewrite_tag( '%artist%', '([^/]+)' );
add_rewrite_rule(
'songs/([^/]+)/([^/]+)?$',
'index.php?artist=$matches[1]&songs=$matches[2]',
'top'
@cameronjonesweb
cameronjonesweb / gform-field-content-filter.php
Created Feb 16, 2020
Render the_content in a gravity forms field
View gform-field-content-filter.php
<?php
$form_id = 1;
$field_id = 1;
add_filter( "gform_field_content_{$form_id}_{$field_id}", 'gfield_render_the_content', 10, 5 );
function gfield_render_the_content( $content, $field, $value, $lead_id, $form_id ) {
$content = apply_filters( 'the_content', get_the_content() );
return $content;
}
@cameronjonesweb
cameronjonesweb / create-index-php.sh
Last active Oct 7, 2020
Recursively creates an index.php file in all subfolders that don't include an index.php file
View create-index-php.sh
shopt -s globstar
for i in **; do
if [ -d "$i" ]; then
# update this line to include directories to ignore
if [[ "${i##/*}" != *"node_modules"* && "${i##/*}" != *"bower_components"* ]]; then
if [ ! -f "${i##/*}/index.php" ]; then
printf "Creating index file in %s\n" "${i##/*}"
printf "<?php\n// Silence is golden." > ${i##/*}/index.php
fi
fi
@cameronjonesweb
cameronjonesweb / add-field-type-to-class.php
Created Oct 4, 2018
Adds a class that defines the type of field to the <li> element in Gravity Forms
View add-field-type-to-class.php
<?php
add_filter( 'gform_field_css_class', 'cameronjonesweb_add_field_type_to_class', 10, 3 );
/**
* Adds a class that defines the type of field to the li element in Gravity Forms
*
* @param string $css_class The existing CSS classes.
* @param GF_Field $field The field object.
* @param array $form The form object.
* @return string
@cameronjonesweb
cameronjonesweb / functions.php
Last active Oct 7, 2020
Takes custom classes out of the list item and adds them to the anchor element in WordPress menus. Perfect for font icons
View functions.php
<?php
add_filter( 'nav_menu_link_attributes','cameronjonesweb_move_custom_menu_item_class_to_anchor_element', 10, 4 );
add_filter( 'nav_menu_css_class', 'cameronjonesweb_remove_custom_menu_item_class_from_li_element', 10, 4 );
/**
* Get the custom item menu classes and add them to the anchor element
*
* @link https://cameronjonesweb.com.au/blog/how-to-move-the-custom-menu-item-classes-to-the-anchor-element/
* @param array $atts The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
@cameronjonesweb
cameronjonesweb / cameronjonesweb-fix-author-no-posts.php
Created Jul 10, 2017
Fixes an issue with WordPress where the current author is empty on author archives with no posts
View cameronjonesweb-fix-author-no-posts.php
<?php
add_action( 'template_redirect', 'cameronjonesweb_fix_author_no_posts' );
function cameronjonesweb_fix_author_no_posts() {
global $authordata;
if( is_author() && empty( $authordata ) ) {
You can’t perform that action at this time.