Support » Plugins » Hacks » Writing the HTML output of a Dynamic Sidebar to file

  • Resolved GreenLead


    I need to write the HTML output of a sidebar and the widgets contained inside it into a text file.

    However, whilst calling dynamic_sidebar() and specifying the location does display the output, it simply returns “true” to the PHP code. Is there a way to get the actual HTML output and write that to a file instead?

Viewing 1 replies (of 1 total)
  • To answer my own question and hopefully help others facing similar problems, here’s my solution:

    (Take note of the annotations)

    	// Put this at the start of the script
    	// Initialize WordPress, etc
    	Load the contents of a widget area.
    	Usually, dynamic_sidebar only returns "true" upon a successful function call, but as we'll see later on, the HTML output that is sent to the browser can be captured and saved to a file
    	dynamic_sidebar( 'top-widget-area' );
    	// Get the contents of the file, which obstensibly contains the desired HTML output of the widget
    	$page = ob_get_contents();
    	// Write the contents to a text file
    	$fp = fopen("menu.txt","w");
Viewing 1 replies (of 1 total)
  • The topic ‘Writing the HTML output of a Dynamic Sidebar to file’ is closed to new replies.