Connect Second Database to WordPress

I have found that the following works for connecting the database via the theme’s functions.php file. I placed this code snippet at the end of the existing code in the file. Even though the fatal error threw several line errors when trying to access the site, it only came down to wpdb having an extra … Read more

How do i get (unique) page name?

The WP global variable $pagename should be available for you, I have just tried with the same setup you specified. $pagename is defined in the file wp-includes/theme.php, inside the function get_page_template(), which is of course called before your page theme files are parsed, so it is available at any point inside your templates for pages. … Read more

Where to save common libraries?

I would recommend creating a plugin that holds all of your libraries. In the main plugin file, set a constant that defines the path to the plugin folder so you can easily include the files with your other plugins/themes.

Beautify WordPress HTML output without any plugins

Great question, I asked it myself and here’s what I came up with. You can just use this in a custom plugin or in functions.php. // turn on Output Buffering (hence *ob*) ob_start(); // register a callback to run after WordPress has outputed everything add_action(‘shutdown’, function () { // get the output buffer and store … Read more