3 years ago
<?php
/**
* add custom layout builder tag for to retrieve the url of the featured image at a specified size
* 'medium' can be changed to any default or custom wp image size
* https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/#image-sizes
**/
add_filter( 'facetwp_builder_dynamic_tags', function( $tags, $params ) {
$tags['attachment:url'] = wp_get_attachment_image_url( get_post_thumbnail_id(), 'medium' );
return $tags;
}, 10, 2 );
/** -----------------------------------------------------
** alternative with default image url
** ----------------------------------------------------- */
/**
* add custom layout builder dynamic tag for to retrieve the url of the featured image at a specified size
* 'medium' can be changed to any default or custom wp image size
* https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/#image-sizes
* change 'http://example.com/image.jpg' to a default image to use when no image url is found
**/
add_filter( 'facetwp_builder_dynamic_tags', function( $tags, $params ) {
$tags['attachment:url'] = ( $image = wp_get_attachment_image_url( get_post_thumbnail_id(), 'medium' ) ) ? esc_url( $image ) : 'http://example.com/image.jpg';
return $tags;
}, 10, 2 );
4 years ago
<?php
/** attachemnt url dynamic tag
** for use when results are media type posts
** IMPORTANT: does not check that post type is valid attachment type **/
add_filter( 'facetwp_builder_dynamic_tags', function( $tags, $params ) {
$tags['attachment:url'] = esc_url( wp_get_attachment_url( $params['post']->ID ) );
return $tags;
}, 10, 2 );