Archive: January 2023

WordPress use PHP & JavaScript in Widgets

Resolve adding the following code to the WordPress theme function.php file. HIGHLY recommend creating a child theme and using functions.php from that theme. add_filter('widget_text','execute_php',100); function execute_php($html){ if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html); $html=ob_get_contents(); ob_end_clean(); } return $html; } To enable shortcodes in the Text

No Cache for Apache

Navigate to your httpd.conf file (xamppapacheconf) and open it using your favourite text editor. If you do not have access to this folder/file, open your .htaccess file instead. Underneath the "#LoadModule" lines, add the following: # Instruct the browser to always check for the latest version of your files using Apache directives <IfModule mod_headers.c> <FilesMatch

PDF.js Open Links in New Tab

Since the release of PDF.js 2.0.943 you can force URL to open in a new tab: <script> function applyConfig() { PDFViewerApplication.preferences.set('externalLinkTarget', 2); } document.addEventListener('DOMContentLoaded', applyConfig, true); </script> Older versions we used: PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK; This is also a hack that might work on newer versions but

Load PDF into PHP File

This code shows using a database but can easily be adopted for direct use. // Database Connection $conn = new mysqli('hostname', 'username', 'password', 'database'); //Check for connection error $select = "SELECT * FROM `infopdf`"; $result = $conn->query($select); while($row = $result->fetch_object()){ $pdf = $row->filename; $path = $row->directory; $date = $row->created_date;

Basic PHP File Cache

cache.php content: class CachingClass { var $cache_time = null; var $file_name = null; function __construct( $file_name, $cache_time = 0 ) { $this->cache_time = ( $cache_time > 0 ) ? $cache_time : (300 * 60); $this->file_name = $file_name; } function startBuffering( ) { ob_start(); } function stopBuffering( ) { $fp = fopen($this->file_name, 'w'); fwrite($fp, ob_get_contents());

Changing WordPress Admin Password From PhpMyAdmin

So you forgot your WordPress password... Login to hosting control panel Go to PhpMyAdmin Click on your WordPress database and view list of tables in the database. Locate the 'wp_users' table. If you have changed the table prefix during the WordPress installation, then look for 'prefix_wp_users' table. Click on the browse link next to it. You should now see entries in your WordPress users table.