3 years 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 );
3 weeks ago
<?php
// Note: in FacetWP 4.3.2 the facetwp_i18n hook was added to the Button item, making it easier to translate the Button text.
// See: https://facetwp.com/help-center/listing-templates/listing-builder/#translate-the-button-item-text
// The solutions below can still be used for older FacetWP versions and other items.
// To tranlate a Button item's Button text:
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'el-2epdx' == $item['settings']['name'] ) { // Replace 'el-2epdx' with the name of your listing builder item
$lang = ( ! empty( FWP()->facet->http_params['lang'] ) ) ? FWP()->facet->http_params['lang'] : apply_filters( 'wpml_current_language', null );
switch ( $lang ) {
case 'en' :
$value = 'My english button text';
break;
default :
$value = 'Default button text';
}
}
return $value;
}, 10, 2 );
// If the Button has a link set, use this instead:
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'el-pgnldu' == $item['settings']['name'] ) { // Replace 'el-2epdx' with the name of your listing builder item
$lang = ( ! empty( FWP()->facet->http_params['lang'] ) ) ? FWP()->facet->http_params['lang'] : apply_filters( 'wpml_current_language', null );
switch ( $lang ) {
case 'en' :
$text = 'My english button text';
break;
default :
$text = 'Default button text';
}
$dom = new DOMDocument();
$dom->loadHTML($value);
$link = $dom->getElementsByTagName('a')->item(0);
$link->nodeValue = $text;
$value= $dom->saveHTML();
}
return $value;
}, 10, 2 );
7 months ago
<?php
// Set your Post Author Listing Builder item's 'Author field' setting to 'User ID'.
// Replace 'my-author-item' with the 'Unique name' of your Post Author builder item.
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if( $item['settings']['name'] == 'my-author-item' ) {
$author_id = $value;
$author_link = get_author_posts_url( $author_id );
$author_name = get_the_author_meta( 'display_name', $author_id );
return '<a href="' . $author_link . '">'. $author_name . '</a>';
}
return $value;
}, 10, 2 );
2 years ago
<?php
/** returns blank for a wpbakery page value, for replace excerpts in layout builder that show wpbakery shortcodes
** WPBakery does not process its shortcodes during an ajax request
**/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
if ( 'el-omcatx' == $item['settings']['name'] ) { // change 'el-omcatx' to the name of your setting
if ( true == get_post_meta( get_the_id(), '_wpb_vc_js_status', true ) ) {
$value = '';
}
}
return $value;
}, 10, 2 );
2 years 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 );
2 years 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 );
3 weeks ago
<?php
// Note: in FacetWP 4.3.2 the facetwp_i18n hook was added to the Button item, making it easier to translate the Button text.
// See: https://facetwp.com/help-center/listing-templates/listing-builder/#translate-the-button-item-text
// The solution below can still be used for older FacetWP versions and other items.
// Allows for 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 );
3 years 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 );
4 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 );
4 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 );