Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Este snippet busca o primeiro embed do post, seja através de shortcode (exemplo: [facebook url="https://www.facebook.com/usuario/posts/id-do-post"]
- * ou usando o auto embed postando apenas a url (exemplo: https://www.facebook.com/usuario/posts/id-do-post.
- * Se for um shortcode, usamos "get_shortcode_regex" (http://codex.wordpress.org/Function_Reference/get_shortcode_regex) e "do_shortcode" (http://codex.wordpress.org/Function_Reference/do_shortcode).
- * Se for um autoembed, usamos "wp_oembed_get" (http://codex.wordpress.org/Function_Reference/wp_oembed_get).
- */
- // No functions.php
- function temabase_get_embed_content() {
- global $post, $posts, $wp_embed;
- $pattern = get_shortcode_regex();
- ob_start();
- ob_end_clean();
- if ( preg_match_all('/' . $pattern . '/s', $post->post_content, $matches) ) {
- echo do_shortcode($matches [0] [0]);
- }
- elseif ( preg_match_all('|^\s*(https?://[^\s"]+)\s*$|im', $post->post_content, $matches) ) {
- $embed_code = wp_oembed_get($matches [1] [0]);
- echo $embed_code;
- } else {
- echo the_except();
- }
- }
- // No loop (content.php ou similar)
- echo temabase_get_embed_content();
Advertisement
Add Comment
Please, Sign In to add comment