Tuesday, June 26th, 2018
Make sure your image field is set to an array in ACF and then use the below.
‘150px’ is the maximum width your image will ever display.
Click the link to view the code
Tags: ACF, Functions, Responsive images, SRCSET, WordPress
Posted in PHP, WordPress | No Comments »
Thursday, June 14th, 2018
This will go in taxnonomy.php or taxonomy-name.php templates.
$term = get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') );
$customField = get_field('custom_field_name')];
$args = array(
'posts_per_page' => '-1',
'post_type' => 'service_centres',
'tax_query' => array (
array (
'taxonomy' => 'regions',
'field' => 'slug',
'terms' => $term->slug
)
),
'meta_key' => 'custom_field_name',
'meta_value' => 'custom_field_value_value'
);
Tags: PHP, Query, Taxonomy, Term, Terms, WordPress
Posted in PHP, WordPress | No Comments »
Monday, April 16th, 2018
Function for grabbing image from post and using it instead of a featured image for example.
Add this to functions.php
// Get URL of first image in a post
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$matches[1][0] = '';
if(preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches)){
$first_img = $matches[1][0];
}
// no image found display default image instead
return $first_img;
}
And call in the theme with
<img src="<?php echo catch_that_image() ?>" onerror="this.style.display = 'none';"/>
Tags: catch that image, featured image, first image, first image from post, Functions, PHP, wordperss
Posted in PHP, WordPress | No Comments »
Tuesday, January 9th, 2018
Add this to you wp-config.php file and change the number for how many revisions you want to limit your pages to:
define('WP_POST_REVISIONS', 10);
Or use the below to globally turn off post revisions:
define('WP_POST_REVISIONS', false);
Tags: Code help, Functions, Matt Seymour, Post, Revisions, Support, WordPress, WP, WP config, wp_post_revisions
Posted in PHP, WordPress | No Comments »
Thursday, December 1st, 2016
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
the_field('custom_field_name', $queried_object);
Tags: Custom tax, Custom taxonomy, ID, Slug, Taxonomy, Term, WordPress
Posted in PHP, WordPress | No Comments »
Wednesday, November 30th, 2016
Add this to functions.php
// Pick out the version number from scripts and styles
function remove_version_from_style_js( $src ) {
if ( strpos( $src, 'ver=' . get_bloginfo( 'version' ) ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_version_from_style_js');
add_filter( 'script_loader_src', 'remove_version_from_style_js');
Tags: Functions, PHP, Remove, Script, Style, Ver, Version, WordPress
Posted in PHP, WordPress | No Comments »
Monday, October 24th, 2016
Use the PHP in the query below – and then the HTML example below to echo the URL out.
the_post_thumbnail_url(); // without parameter -> 'post-thumbnail'
the_post_thumbnail_url( 'thumbnail' ); // Thumbnail (default 150px x 150px max)
the_post_thumbnail_url( 'medium' ); // Medium resolution (default 300px x 300px max)
the_post_thumbnail_url( 'large' ); // Large resolution (default 640px x 640px max)
the_post_thumbnail_url( 'full' ); // Full resolution (original size uploaded)
the_post_thumbnail_url( array(100, 100) ); // Other resolutions
Tags: Echo, Query, Thumbnail, URL, WordPress
Posted in PHP, WordPress | No Comments »