Current child post or page parent title and link, Dynamic Data Tag
{parent_link}
just coded this custom data tag snippet it may be useful for someone else too.
enjoy
add_filter( 'bricks/dynamic_tags_list', 'register_parent_link_tag' );
function register_parent_link_tag( $tags ) {
$tags[] = [
'name' => '{parent_link}',
'label' => 'Parent Title and Link',
'group' => 'Custom Tags',
];
return $tags;
}
add_filter( 'bricks/dynamic_data/render_tag', 'render_parent_link_tag', 10, 3 );
function render_parent_link_tag( $tag, $post, $context = 'text' ) {
if ( $tag !== 'parent_link' ) {
return $tag;
}
if ( $post->post_parent ) {
$parent_post = get_post( $post->post_parent );
if ( $parent_post ) {
$parent_title = get_the_title( $parent_post );
$parent_link = get_permalink( $parent_post );
return '<a href="' . esc_url( $parent_link ) . '">' . esc_html( $parent_title ) . '</a>';
}
}
return 'No Parent Found';
}
add_filter( 'bricks/dynamic_data/render_content', 'render_parent_link_tag_in_content', 10, 3 );
function render_parent_link_tag_in_content( $content, $post, $context = 'text' ) {
if ( strpos( $content, '{parent_link}' ) !== false ) {
$parent_link = render_parent_link_tag( 'parent_link', $post, $context );
$content = str_replace( '{parent_link}', $parent_link, $content );
}
return $content;
}