'; $click_to_copy = "
$copied
"; $dom = dom( $html ); $pre = get_dom_element( 'pre', $dom ); $code = get_dom_element( 'code', $dom ); $element = $pre ?? $code ?? null; if ( ! $element ) { return $html; } $copy_dom = dom( $click_to_copy ); $div = get_dom_element( 'div', $copy_dom ); $imported = $element->ownerDocument->importNode( $div, true ); $element->insertBefore( $imported, $element->firstChild ); $html = $dom->saveHTML(); return $html; } add_filter( 'blockify_inline_js', NS . 'add_click_to_copy', 10, 2 ); /** * Add click to copy JS. * * @since 0.9.34 * * @param string $js Inline JS. * @param string $html Page HTML content. * * @return string */ function add_click_to_copy( string $js, string $html ): string { if ( str_contains( $html, 'click-to-copy' ) ) { $js .= file_get_contents( DIR . 'assets/js/clickToCopy.js' ); } return $js; }