PHP WordPress - Create Codepad.co Snippet Image Embed

<?php wp_embed_register_handler( 'codepad_co_snippet', '#https?://codepad\.co/snippet/([^/]+)#', 'wp_embed_handler_codepad_co_snippet' ); function wp_embed_handler_codepad_co_snippet( $matches, $attr, $url, $rawattr ) { $snippet_id = esc_attr( $matches[ 1 ] ); $snippet_url = "https://codepad.co/snippet/${snippet_id}"; $img_src = "https://codepad.co/img/snippets/${snippet_id}.png"; $embed = sprintf( '<div class="codepad_co_snippet"><a target="_blank" href="%s" > <img src="%s" alt="%s" width="550px" height="490px" title="Codepad.co Snippet %s - Embed by Jesse Graupmann" /></a></div>', $snippet_url, $img_src, $snippet_id, $snippet_id ); return apply_filters( 'embed_codepad_co_snippet', $embed, $matches, $attr, $url, $rawattr ); } // TEST // ========================================================== // echo wp_oembed_get('https://codepad.co/snippet/EuYNZhBd');

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.