Skip to content

Instantly share code, notes, and snippets.

@SteveJonesDev
SteveJonesDev / gist:c67e673b5f0828b4b738d5f4581c0005
Created January 25, 2017 03:46 — forked from markoheijnen/gist:2407319
Get WordPress menu title by theme location
<?
function get_menu_title( $theme_location, $default_name = 'menu' ) {
if ( $theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $theme_location ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $theme_location ] );
if( $menu && $menu->name ) {
return $menu->name;
}
}
@SteveJonesDev
SteveJonesDev / functions.php
Last active February 7, 2017 03:27
Wordpress WP_User_Query - Query by meta with random ordering
<?php
/*
WP_User_Query orderby random
put this in functions.php
*/
add_filter('pre_user_query', function(&$query) {
if($query->query_vars["orderby"] == 'rand') {
$query->query_orderby = 'ORDER by RAND()';
}
});
@SteveJonesDev
SteveJonesDev / functions.php
Created May 9, 2018 18:41
How to insert custom code into the WordPress post content
<?php // dont include this line
//Insert code after second paragraph of single post content.
add_filter( 'the_content', 'sj_insert_code' );
function sj_insert_code( $content ) {
$code = '<div>Code to be inserted goes here</div>';
if ( is_single() && ! is_admin() ) {
return sj_insert_after_paragraph( $code, 2, $content );
}
return $content;
@SteveJonesDev
SteveJonesDev / functions.php
Created May 10, 2018 18:30
Add class to links generated by next_posts_link and previous_posts_link
add_filter('next_posts_link_attributes', 'posts_link_attributes');
add_filter('previous_posts_link_attributes', 'posts_link_attributes');
function posts_link_attributes() {
return 'class="button"';
}
@SteveJonesDev
SteveJonesDev / functions.php
Created October 16, 2018 14:13
WordPress Admin Branding Include
/*
Admin Branding
*/
$admin_branding_url = get_stylesheet_directory() . '/includes/admin-branding.php';
if(file_exists($admin_branding_url)) {
include_once($admin_branding_url);
}
@SteveJonesDev
SteveJonesDev / functions.php
Last active June 5, 2019 14:39
Wordpress - Change Enter Title Here Text
add_filter('enter_title_here', 'my_title_place_holder' , 20 , 2 );
function my_title_place_holder($title , $post){
if( $post->post_type == 'pet' ){
$my_title = "Animal Name";
return $my_title;
}
return $title;
}
@SteveJonesDev
SteveJonesDev / functions.php
Created July 9, 2019 17:43
Add Custom Color Palette to ACF Pro Color Picker Field
function sjd_acf_input_admin_footer() {
?>
<script type="text/javascript">
(function($) {
acf.add_filter('color_picker_args', function( args, $field ){
// add the hexadecimal codes here for the colors you want to appear as swatches
args.palettes = ['#ffffff','#000000']
@SteveJonesDev
SteveJonesDev / functions.php
Created July 9, 2019 20:25
Change featured image size on a specific archive page in Genesis
// Change featured image size on a specific archive page
function sjd_custom_loop_image_size( $image_size ) {
if(is_archive('testimonial')){
$image_size = 'content-slider';
return $image_size;
}
}
add_filter( 'genesis_pre_get_option_image_size', 'sjd_custom_loop_image_size' );
@SteveJonesDev
SteveJonesDev / functions.php
Created July 19, 2019 15:54
Add custom avatar size to Genesis user profile widget
// add custom avatar size to Genesis user profile widget
add_filter( 'genesis_gravatar_sizes', 'sjd_user_profile' );
function sjd_user_profile( $sizes ) {
$sizes['Extra Large Image'] = 200;
return $sizes;
}
@SteveJonesDev
SteveJonesDev / functions.php
Created March 2, 2021 19:14
Accessibility Checker Filter Readability Score Content
add_filter('edac_filter_readability_content', 'edadc_custom_readability_content', 1, 2);
function edadc_custom_readability_content($content, $post_id){
$content .= get_field('my_custom_field',$post_id);
return $content;
}