Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save seemly/e54e866472f404181b4e6b78a7c6148b to your computer and use it in GitHub Desktop.
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
<?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