Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ibrahim-kardi/ccb671f1deb27e5f2a15680e007f81c7 to your computer and use it in GitHub Desktop.
Save ibrahim-kardi/ccb671f1deb27e5f2a15680e007f81c7 to your computer and use it in GitHub Desktop.
override specific gutenberg block function
if (has_block("gallery", get_the_content()))
{
$post_blocks = parse_blocks(get_the_content());
foreach ($post_blocks as $post_block)
{
if ("core/gallery" == $post_block["blockName"])
{
$ids = $post_block["attrs"]["ids"];
}
}
}
And this is the button:
<button class="gallery"
<?php
for ($i = 0; $i < count($ids); $i++) {
$img_link = wp_get_attachment_image_url($ids[$i], "full");
echo "data-img-" . $i . " = " . $img_link . " ";
}
?>
>
Light Box
</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment