I want to get entire HTML source of a post page of WordPress for that scraping meta-keywords from the HTML.(then want to use the keywords as Twitter hashtags.)

I think up to use callback like the following PHP script but It mistaken idea.

function callback($buffer) {

  // scraping meta and var_dump it
    $meta_tags = getMetaTags($buffer);
    echo var_dump($meta_tags) ; // Not outputed, also not to get value as well

    return $buffer ;


How do you solve it?


The typical way to get "the entire page worth of HTML" is to use the template_redirect hook, it's often used for "run-time find & replace" methods. If I ever need to use it, I just use it in an Anonymous Function.

add_action( 'template_redirect', function(){
    ob_start( function( $buffer ){
        // Do whatever to $buffer - it contains the entire page's HTML output

        return $buffer;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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