1 year ago
<?php
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'website-link' == $item['settings']['name'] ) { // adjust website-link to name of your layout field https://d.pr/i/gL3rjA
if ( !empty( $value ) ) {
$value = '<a href="' . esc_url( $value ) . '">website</a>';
} else {
$value = '';
}
}
return $value;
}, 10, 2 );
2 months ago
<?php
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'social-icons' == $item['settings']['name'] ) {
$output = '';
$names = explode( ', ', $value ); // get the individual names
$names = array_map( 'strtolower', $names ); // convert to lowercase
foreach ( $names as $name ) {
$output .= '<img src="/path/to/' . $name . '.jpg" alt="' . $name . '" /> ';
}
return $output;
}
return $value;
}, 10, 2 );
4 months ago
/**
** Some metabox fields don't save the right value for display, this can be used to output with metabox function to get correct display value
** 'el-99ck4' is name in the item settings in layout builder,
** see https://facetwp.com/help-center/developers/hooks/output-hooks/facetwp_builder_item_value/
** change 'name_for_meta' to the name of the meta box field, see for more info and additional
** functions for getting meta https://docs.metabox.io/displaying-fields/
**/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'el-99ck4' == $item['settings']['name'] ) {
$value = rwmb_meta( 'name_for_meta' );
}
return $value;
}, 10, 2 );
8 months ago
<?php
/** allows string translation from pll_register_string in layout builder **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'my-item' == $item['settings']['name'] ) {
$current = ( !empty( FWP()->facet->http_params['lang'] ) ) ? FWP()->facet->http_params['lang'] : pll_current_language();
$value = pll_translate_string( 'Read More', $current );
}
return $value;
}, 10, 2 );
1 year ago
<?php
/** convert time sources for wp recipe manager to hour / min values **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( preg_match( '/wprm\/([a-zA-Z]+)_time/', $item['source'], $matches ) ) {
if ( !empty( $matches ) ) {
$type = $matches[1];
} else {
return $value;
}
$recipe_id = get_the_ID();
if ( 'post' == get_post_type( get_the_ID() ) ) {
$recipe_ids = WPRM_Recipe_Manager::get_recipe_ids_from_post( get_the_ID() );
if ( !empty( $recipe_ids ) ) {
$recipe_id = array_shift( $recipe_ids );
}
}
if ( 0 < $recipe_id) {
return do_shortcode( '[wprm-recipe-time type="' . $type . '" id=" ' . $recipe_id . '"]' );
}
}
return $value;
}, 10, 2 );
2 years ago
<?php
/**
** for creating custom image sizes
** https://developer.wordpress.org/reference/functions/add_image_size/
**/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'my-image' == $item['settings']['name'] && !empty( $value ) ) { // change 'my-image' to the unique name of your field
$image = get_field('acf_image_field'); // change 'acf_image_field' to the name of your acf field
if ( $image ) $value = wp_get_attachment_image( $image, 'thumbnail' ); // 'thumbnail' can be changed to other image sizes you have available
}
return $value;
}, 10, 2 );
2 years ago
<?php
/** use do_shortcode on all layout builder items
** it is preferrable to target specific items
** as in https://facetwp.com/documentation/developers/output/facetwp_builder_item_value/
** if possible
**/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
$value = do_shortcode( $value );
return $value;
}, 10, 2 );
2 years ago
<?php
// Insert the following code into your (child) theme's functions.php
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'personal-photo' == $item['settings']['name'] && !empty( $value ) ) {
$value = wp_get_attachment_image( $value, 'full' ); // 'full' can be changed to other image sizes
}
return $value;
}, 10, 2 );
2 years ago
<?php
/**
* This pulls the avatar (profile photo) from the "User Profile Picture" plugin
* Add a layout builder item (named "avatar") and using the data source of "User ID"
*/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'avatar' == $item['settings']['name'] ) {
$value = get_avatar( $value );
}
return $value;
}, 10, 2 );
2 years ago
<?php
/**
* Add to your (child) theme's functions.php
*
* We've added a layout builder item (named "email-md5"), based on the "User Email" field, and set to Hidden
* We've also added a new HTML item with the following content:
*
* <img src="https://www.gravatar.com/avatar/{{ email-md5 }}?s=200" />
*
* This generates the user's profile image (based on Gravatar)
*/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'email-md5' == $item['settings']['name'] ) {
$value = md5( $value );
}
return $value;
}, 10, 2 );