This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $categories = get_the_category(); | |
| if ( ! empty( $categories ) ) { | |
| $first_category = $categories[0]; | |
| $first_category_name = esc_html( $first_category->name ); | |
| $first_category_link = esc_url( get_category_link( $first_category->term_id ) ); | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Because WP does not allow us to set minimum image dimensions on upload we often | |
| * use an ACF image. However this means within the dashboard we lack a thumbnail | |
| * Here we set the ACF image to be the WP thumbnail. | |
| */ | |
| function image_to_thumbnail( $post_id ) { | |
| if( get_post_type($post_id) != 'talent' ) { | |
| return; // Stop if post-type is not talent | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Convert UK shoe size to European size | |
| function euro_shoe( $uk_size ) { | |
| $eu_size = null; | |
| if( ! is_numeric( $uk_size ) ) { | |
| return $eu_size; // Abort if we are NOT dealing with a number | |
| } | |
| if ( in_array($uk_size, range(2, 19, 0.5)) ) { | |
| // Check to make sure it is a sensible shoe size number using a range with half size steps | |
| // Now work through the equation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Return age in years from date of birth | |
| function get_age( $date_of_birth = 0 ) { | |
| $age = null; | |
| if( strtotime( $date_of_birth ) ) { | |
| $date_today = new DateTime('today'); | |
| $date_of_birth = new DateTime($date_of_birth); | |
| $age = $date_of_birth->diff($date_today)->y; | |
| } | |
| return $age; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * A function to split the post title into first and last names, | |
| * We assume everything up to the first whitespace is the first name, | |
| * the rest is considered the last name. | |
| */ | |
| function get_names( $full_name ) { | |
| if( $full_name ) { | |
| $full_name = sanitize_text_field($full_name); // remove nasties | |
| /** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Removes the default editor | |
| add_action('admin_head', 'hide_editor'); | |
| function hide_editor() { | |
| $template_file = $template_file = basename(get_page_template()); | |
| $excluded = array( | |
| 'home-page.php', | |
| 'search-page.php' | |
| ); | |
| foreach ($excluded as $template){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // A generic responsive image helper | |
| function responsive_image( $acf_image_array, $alt, $sizes, $srcset, $class = null ) { | |
| $default_image_url = get_bloginfo( 'template_directory' ) . '/assets/img/thumb_blank.svg'; | |
| $filetype_ext = 'svg'; | |
| if( !empty( $acf_image_array ) ) { | |
| $image_url = $acf_image_array['url']; | |
| $filetype = wp_check_filetype($image_url); | |
| $filetype_ext = $filetype['ext']; | |
| if( $filetype_ext == 'svg' ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Function to wrap last word in span | |
| function last_word_wrap($string, $class = null) { | |
| $span = '<span'; | |
| if( $class ) { | |
| $span .= ' class="' . $class . '"'; | |
| } | |
| $span .= '>'; | |
| $wrapped = preg_replace('/\s(\S*)$/', ' ' . $span . '$1', $string); | |
| $wrapped .= '</span>'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% if not page.fileSlug|length %} | |
| This is the home page<br> | |
| We know this as the homepage has no slug<br> | |
| So when we use a filter to get the length of the page slug it returns false if we are on the homepage<br> | |
| So if we preceed that test with an if not conditional we know we are on the homepage<br> | |
| We are essentially saying if the page slug is empty do something. | |
| Also see it used in a ternary style arrangment below. | |
| {% endif %} | |
| {{ title if page.fileSlug|length else heading }} |