Last active
October 22, 2024 14:46
-
-
Save seemly/e54e866472f404181b4e6b78a7c6148b to your computer and use it in GitHub Desktop.
Replace GeneratePress dynamic content 'title' value in custom taxonomy archive page defined in Elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( | |
"render_block", | |
function ($block_content, $block) { | |
$should_replace_title = ("title" === $block["attrs"]["gpDynamicTextType"]); | |
if (is_tax("your-custom-taxonomy") && $should_replace_title) { | |
// Get the dynamically defined text we want to replace. | |
$text_to_replace = $block["attrs"]["gpDynamicTextReplace"]; | |
// Define the new text | |
$new_text = single_term_title("", false); | |
// Update innerHTML content to maintain styling defined in Elements. | |
$block["innerHTML"] = str_replace( | |
$text_to_replace, | |
$new_text, | |
$block["innerHTML"] | |
); | |
// set $block_content to new value. | |
$block_content = $block["innerHTML"]; | |
} | |
return $block_content; | |
}, 15, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment