0

Recently I was stuck by an idea to let users and other bloggers to embed the entire page on of my blog on to their blogs. The problem is I have to change the URL every time in code and the codes populate the result on my page itself.

Is there any way by which the script could automatically fetch the URL of the viewing page and update it codes for users without generating the content on my page? This is what I was trying.

    <object data=http://domain.tld/Requested_page width="100%" height="500"> 
        <embed src=http://domain.tld/Requested_page width="100%" height="500"></embed> Error: Embedded data could not be displayed. Visit 
        <a title="Title of requested Page" href="http://domain.tld/Requested_page">Visit</a>
    </object>
2
  • How are you generating the embed code? Any shortcode or any function? Commented Sep 8, 2014 at 10:39
  • manually!! This set of code is what i use to embed my blog post on my tumblr account. I have to change the URL every time before i post.
    – lucas
    Commented Sep 8, 2014 at 17:06

1 Answer 1

0

Try following code. This will display embed code in the bottom of the page.

<?php
add_filter('the_content','my_custom_embed_code');
function my_custom_embed_code( $content ){
  global $post;

  if ( 'page' == $post->post_type ) {
    $embed_code = '';
    $page_url = esc_url( get_permalink($post->ID ) ) ;
    $embed_code .= '<object data='.$page_url.' width="100%" height="500"><embed src='.$page_url.' width="100%"   height="500"></embed> Error: Embedded data could not be displayed.     Visit <a title="'.esc_attr($post->        post_title).'" href="'.$page_url.'">Visit</a></object>';
    $content = $content . '<div class="embed-wrap">'.esc_html($embed_code).'</div>';
  }
  return $content;

}
1
  • It's not working. Neither it worked when pasted in functions.php nor when pasted in widget available under post.
    – lucas
    Commented Sep 9, 2014 at 3:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.