Skip to content

Instantly share code, notes, and snippets.

@bhalash
Last active March 20, 2016 20:56
Show Gist options
  • Select an option

  • Save bhalash/b76a93c69a502d2b66e3 to your computer and use it in GitHub Desktop.

Select an option

Save bhalash/b76a93c69a502d2b66e3 to your computer and use it in GitHub Desktop.
WordPress post content content replacement
add_filter('the_content', function($content) {
$bindings = [
'<img' => ['click: lightbox.show']
];
foreach ($bindings as $tag => $directives) {
$directive = sprintf('%s data-bind="%s" ', $tag, implode(', ', $directives));
$content = str_replace($tag, $directive, $content);
// <img data-bind="click: lightbox.show"
}
return $content;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment