-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supports Bricks Builder Dynamic Data (DD). #683
Comments
We currently have no intention to expose TSF's data for display other than aimed at search engines. The breadcrumbs shortcode was postponed by a few years for this reason. Bricks's Dynamic Data could interpret existing meta fields, for example, via For now, the same doesn't apply to TSF's post metadata (their documentation doesn't say how to access post meta). But I'm planning to convert this data to a key-value store as well: #185. Bricks does have something to access array values; however, it is unclear to me if this could be applied to what we currently offer. I think if we were to implement this, we'd indeed need to create custom dynamic data. Here's an example (untested, based on their documentation): add_filter(
'bricks/dynamic_tags_list',
/**
* @param array $tags
*/
function ( $tags ) {
$tags[] = [
'name' => '{tsf_post_meta}',
'label' => 'The SEO Framework post metadata',
'group' => 'The SEO Framework',
];
return $tags;
},
);
add_filter(
'bricks/dynamic_data/render_tag',
/**
* @param string $tag
* @param WP_Post $post
*/
function ( $tag, $post ) {
if ( ! str_starts_with( $tag, 'tsf_post_meta:' ) )
return $tag;
if ( ! function_exists( 'tsf' ) )
return '';
$tag_parts = explode( ':', $tag );
switch ( $tag_parts[1] ?? '' ) {
case 'title':
return tsf()->get_title( [ 'id' => $tag_parts[2] ?? $post->ID ] );
case 'description':
return tsf()->get_description( [ 'id' => $tag_parts[2] ?? $post->ID ] );
case 'canonical_url':
return tsf()->get_canonical_url( [ 'id' => $tag_parts[2] ?? $post->ID ] );
}
return '';
},
10,
2,
); With that, here's how you get the title for post ID 42:
You can also omit the
I hope this helps :) |
Hi @sybrew , Thank you very much for your attention to my request. ❤️ I'm currently very interested in the fact that TSF has Bricks Dynamic Data that are single data fields stored in _postmeta. Like "Social Image" is one of the things I'm most interested in today. Could you please prioritize Bricks DD development for the single data fields (not arrays) of the TSF stored in _postmeta first? I'm trying to create a plugin to make calling TFS's Social Image via Bricks DD easy and in accordance with Bricks' code standards. I followed the Bricks instructions and documentation but I'm having problems. This is my code. <?php
/**
* Plugin Name: @Dev - TSF and Bricks DD
* Version: 1.0.1
*/
add_filter( 'bricks/dynamic_tags_list', 'tsf_dynamic_data_tags_list', 10, 1 );
add_filter( 'bricks/dynamic_data/render_tag', 'tsf_social_image_render_tag', 10, 3 );
add_filter( 'bricks/dynamic_data/render_content', 'tsf_social_image_render_content', 10, 3 );
add_filter( 'bricks/frontend/render_data', 'tsf_social_image_render_content', 10, 2 );
function tsf_dynamic_data_tags_list( $tags ) {
$tags[] = [
'name' => '{tsf_social_image}',
'label' => 'Social Image',
'group' => 'The SEO Framework',
];
return $tags;
}
function tsf_social_image_render_tag( $tag, $post, $context = 'text' ) {
if ( $tag !== 'tsf_social_image' ) {
return $tag;
}
$post_id = $post->ID;
$social_image_data = tsf_social_image_tag_logic( $post_id, $context );
return $social_image_data;
}
function tsf_social_image_render_content( $content, $post, $context = 'text' ) {
if ( ! str_contains( $content, '{tsf_social_image}' ) ) {
return $content;
}
$post_id = $post->ID;
$social_image_data = tsf_social_image_tag_logic( $post_id, $context );
$content = str_replace( '{tsf_social_image}', $social_image_data, $content );
return $content;
}
function tsf_social_image_tag_logic( $post_id, $context ) {
$social_image_id = get_post_meta( $post_id, '_social_image_id', true );
$social_image_id = ! empty( $social_image_id ) ? $social_image_id : '';
$social_image_data = $social_image_id;
if ( $context === 'image' ) {
$social_image_data = ( ! empty( $social_image_id ) ) ? [ $social_image_id ] : [];
}
return $social_image_data;
} Bricks DD displays fine in Builder like my Screenshot: If I call Dynamic Data Tag {tsf_social_image} in "Heading Element" I get "_social_image_id" as I expected. But if I call {tsf_social_image} on an "IMAGE" Element I get an error message. According to Bricks' instructions, when we want to Render Image Dynamic Data for Image Element, we need to return an array of image IDs. Here is a link related to that issue. https://forum.bricksbuilder.io/t/dynamic-data-not-rendered-correctly-on-image-element/22641/ I have tried many ways but still stuck here. This is the error message.
Can you assist me in correcting this issue? If you need a dev site for this issue with Bricks License, please message me. Looking forward to your help 🐻 |
I'm also very interested about using dynamic data in TSF but I'd primarily like to use dynamic data from custom fields (for example |
I parked this issue for reconsideration, but I didn't see the part where you asked for help with the filters. Sorry about that, @datgausaigon. It appears your code is mixing arrays and strings. The return value to the filters should be a string. Basically, change all instances of @touchdowntech Your request is covered in #140. At #140 (comment), you can see an example filter. I just updated its syntax for TSF v5.0+. |
I currently use Bricks Builder and The SEO Framework (TSF) for many of my Websites.
Bricks Builder, TFS both have very good api support and documentation.
Therefore, I have no difficulty creating Dynamic Data (DD) links between Bricks Builder and TFS.
One of the DDs I find very necessary and use is to call The social image URL (_social_image_url), The social image ID (_social_image_id).
My Post/Page/CPT will have the Featured Image as a square and the Social Image as a horizontal rectangle. It will be very convenient for me to reuse Social Image for display on PC, Desktop, Featured Image for Mobile, or somewhere it will be Social Image or Featured Image in a flexible way.
I created this Feature Request to ask for your feedback on Bricks Builder Dynamic Data (DD) for TSF? It is very useful. Like my Social Image DD as an example.
https://kb.theseoframework.com/kb/data-stored-in-your-database/
https://academy.bricksbuilder.io/article/dynamic-data/
https://academy.bricksbuilder.io/article/create-your-own-dynamic-data-tag/
Thanks
🐻
The text was updated successfully, but these errors were encountered: