Posts

How to Display Custom Wordpress Header with Google Analytics Site Tage and Adwords Site Tag

This post assumes you know how to create custom page templates in Wordpress using child themes. Locate this line of code in your page template (page.php) get_header(); Download the header.php file from the parent theme folder into your child theme folder Rename the header.php file you downloaded to header-with-analytics.php Change the get_header function in your page template to include the custom header file. In the brackets add the custom header filename like this get_header("with-analytics"); Everything after the header- in the filename is what you place between the brackets. Save and upload the custom header PHP file. Upload your modified page template file (page.php) Now the page template will load your custom header file called header-with-analytics.php Place your Google Analytics Site Tag or Google Adwords Conversion Tracking code in this header-with-analytics.php file as per Googles instructions.

How To Add Wordpress Shortcode to PHP Template File

If you're trying to add a Wordpress Shortcode to your custom theme page template you will find that outputting the shortcode in HTML won't work like this: <p>[shortcode here]</p> You will need to use the Wordpress function do_shortcode. This will work <?php echo do_shortcode('[shortcode_here]'); ?>

Eliminate render-blocking JavaScript and CSS

If you use Googles neat PageSpeed Insights tool found here ( https://developers.google.com/speed/pagespeed/insights/ ) you will most likely encounter an optimization suggestion to Eliminate render-blocking JavaScript and CSS in above-the-fold content You can do this by using something called a Critical Path CSS generator Why use this? Without these tweaks a user will see a blank web page when accessing your site in the seconds it takes to render the stylesheets and HTML A Critical Path CSS Generator takes your CSS file contents and filters out the styles needed to load first. Ok, so what do I do then? You simply copy this filtered styles and minify them on www.minifier.org This minifier online tool removes whitespace, strips comments, combines files, and optimizes/shortens a few common programming patterns. You then paste that "minified" code between the <head></head> tags of your webpage with the <style></style> tags But you're...

PHP Mail script to deliver HTML Form data

In your form settings set your action as your link to PHP acript handling the data and your method as POST $name = $_POST['name']; $from = $_POST['email']; $d8time = date("d/m/Y H:i:s"); $to = "brendan@br3nd4nc.blogspot.com"; $subject = "Website Enquiry $d8time"; $headers   = "From: $name <noreply@br3nd4nc.blogspot.com>\r\n";  $headers .= "Content-type: text/html;charset=UTF-8\r\n"; $headers .= "Reply-To: $from\r\n"; $message = "Hello World"; $confirm = mail($to,$subject,$message,$headers); if ($confirm) { print "<script>window.location.replace('http://br3nd4nc.blogspot.com');</script>\n"; } else { print "<h2>Error</h2>"; $errorMessage = error_get_last()['message']; print $errorMessage; //print phpinfo();   }

Complete Uninstall iTunes on Windows 7 Pro 64-Bit

Recently I had an issue with my 64-bit iTunes software on my Windows 7 Professional notebook. iTunes could not be updated to the latest version and I constantly got this error message  "There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support personnel or package vendor." I tried uninstalling iTunes on my PC and re-installing with the same issue. It seems you need to uninstall a few software components related to iTunes. I did this and re-installed iTunes 64-bit on my Windows 7 Pro notebook successfully. Go to your Control Panel and choose "Uninstall a Program" or search the Control Panel (on the top right) with the term "uninstall" to locate the link Uninstall these software components in this exact order to avoid potential issues (as recommended on the Apple website) iTunes Apple Software Update Apple Mobile Device Support Bonjour Apple Applicati...

Editing Existing Theme Function in your Child Theme's functions.php file

By default WordPress assigns a priority of 10 to functions which haven't had a priority added, so to display your function after it you use a number larger than 10 for example 15 like so <?php function child_function() {     // Contents for your function here. } add_action( 'init', 'child_function', 15 ); ?>

Enqueue Stylesheet or Javascript on just one Wordpress Page or Post

To enqueue a css stylesheet or external javascript file on just one page use the following function with a conditional if statement in your child theme functions.php script. function register_online_form_style() {   if ( is_page( '104' ) ) {     wp_enqueue_style( 'contactForm', get_stylesheet_directory_uri() . '/site/css/form.min.css' );   } } add_action( 'wp_enqueue_scripts', 'register_online_form_style' ); 104 is the page or post's ID contactForm is the name of the script Pretty starightforward

Wordpress Define Child Theme Thumbnail Dimensions

To define the thumbnail image dimensions for your Wordpress child theme add this function to your child theme's functions.php file if ( function_exists( 'add_theme_support' ) ) {     add_theme_support( 'post-thumbnails' );     set_post_thumbnail_size( 150, 150, true ); // default Featured Image dimensions (cropped)     // additional image sizes     // delete the next line if you do not need additional image sizes     add_image_size( 'themeName-medium', 400, 220 ); // 400 pixels wide 220 pixels high  }

Write Custom Wordpress Shortcode to use Parameters

So recently I needed to write a Wordpress Shortcode in my Child Theme's functions.php file which allows me to specify certain parameters or variables for a Gallery. If the post did not have any photos for a gallery section it would show a standard set of photos I saved on the server. If the post did have photos for the Gallery I would declare the shortcode with two additional parameters , one for total number of photos (because this runs in a PHP While Loop) and the other for the directory name where the photos are saved. In your functions.php file in your Wordpress Child Theme add this Function (change the names to your preference) function ListingGallery($atts) {   $atts = shortcode_atts( array(         'totalpics' => '10', 'imgdir' => 'general',   ), $atts );      ob_start();      $output_string = ' <h1 class="entry-title">Gallery</h1> <div align="center"...

Disable File Editting in Wordpress Admin Area

It's recommended to disable the File Editor option under Appearances in your Wordpress Admin area by adding these lines to your wp-config.php file /** Disable File Editting within Wordpress */ define('DISALLOW_FILE_EDIT', true);

Password Protect Wordpress Admin folder from the Server's side

1. Create your .htpasswd file by running the following command: htpasswd -c /home/brendan/public_html/.htpasswd your_desired_username (where you should change "your_desired_username" with the actual username that you want to use) 2. With the .htpasswd file now created under your /home/brendan/public_html/ directory, you can go ahead and add the password protection to your wp-login.php file. You can do this by adding the following rules to the .htaccess file in /home/brendan/public_html/: <Files wp-login.php> AuthUserFile /home/brendan/public_html/.htpasswd AuthName "Private access" AuthType Basic require valid-user </Files> 3. Then create a new .htaccess file in your /home/brendan/public_html/wp-admin/ directory and put the following lines in it: AuthUserFile /home/brendan/public_html/.htpasswd AuthName "Private access" AuthType Basic require valid-user <Files admin-ajax.php>   Order allow,deny   Allow from all  ...

How to add links to Javascript files in Wordpress Child Theme using wp_enqueue_script

Took some to figure this out. In your "functions.php" file in your child theme directory add this code function wpb_adding_scripts() { if (!is_admin()) { wp_register_script('my_amazing_script', get_stylesheet_directory_uri() . '/js/scroller.js', array('jquery'),'1.1', true); wp_enqueue_script('my_amazing_script'); } } add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' ); This function checks that you are not logged in as an administrator. my_amazing_script can be named anything you like get_stylesheet_directory_uri() is important if you're doing this in your child theme functions.php file 1.1 is your version number and can be anything true is to load the JS file at the bottom of the page, false is to load the JS file at the top of the page

Sanitize Form Input in PHP to Prevent SQL Injection and Spam

I had to create a custom form recently for my website in Wordpress and had to ensure I cleaned up the input to prevent SQL injection and SPAM.  I could use the Contact Form 7 plugin but I had to format the input before sending via email. I used the strip_tags() and trim() PHP functions to sanitize the input $name = strip_tags(trim($name)); So if the input in the form field for name was:  <a href="www.scam.com" target="_blank">    WIN</a> The output after using these two functions would just be WIN The trim() function cleared the whitespace before the word "win" and the HTML or PHP tags were removed completely

Add Google Conversion Tracking Code to Prestashop CMS page

If you've created a custom thank you or confirmation page in Prestashop and need to place Google Conversion Tracking code in this page follow these steps: In your "themes" folder locate your active theme folder and download the Smarty template file named "cms.tpl" This is the one template file for all CMS pages Because Prestashop uses Smarty the coding differs slightly from PHP Add the following code to the end of the "cms.tpl" file {if $cms->id == 1} {literal} Google Conversion Tracking Code Snippet Goes Here {/literal} {/if} Change 1 to the corresponding ID number in your Prestashop admin site when you create your page. Upload "cms.tpl" back into theme folder

Syncing iTunes playlist on Windows PC to iPhone

After you've installed iTunes on your Windows PC (I use Windows 7 Professional) go to your Music folder and inside the iTunes folder create a folder to store all your media for your phone i.e.: Music, Videos, Tones, eBooks  You can name the folder "Data Store" Open iTunes and go to the relevant media tab e.g.: Music Click on File->Add File to Library... Locate your folder, in this case Data Store and choose the file Once the file is in your iTunes library you sync your library with your iPhone The files in my iTunes library are only for syncing with my phone.  I use VLC Media Player for all my media on my PC otherwise. Connect your iPhone USB data cable.  iTunes will detect your iPhone In iTunes click on the mobile phone icon (top left) Under "Settings" on the left-hand-side ensure you have the Sync option selected for your media types Under "On My Device" on the left-hand-side click on your media type and click "Sync" ...

Generate SALT Keys for Wordpress

When setting up your Wordpress site make sure you add SALT keys to your wp-config.php file. Get these keys generated here: https://api.wordpress.org/secret-key/1.1/salt/ Just copy and paste the 8 lines from the page above into your config file Refresh to generate new keys

Move Wordpress Site to New URL and Web Host

Moving a website and changing your domain name or URLs (i.e. from http://example.com/site to http://example.com , or http://example.com to http://example.net ) requires the following steps - in sequence. Download your existing site files. Export your database - go in to MySQL and export the database. Move the backed up files and database into a new folder - somewhere safe - this is your site backup. Log in to the site you want to move and go to Settings -> General, then change the URLs. (ie from http://example.com/ to http://example.net ) - save the settings and expect to see a 404 page . Download your site files again. Export the database again. Edit wp-config.php with the new server's MySQL database name, user and password. Upload the files. Import the database on the new server. When your domain name or URLs change there are additional concerns. The files and database can be moved, however references to the old domain name or location will remain in the datab...

How To Write your Own Wordpress Plugin

Create your own PHP script usng the following template: <?php /* Plugin Name: Your Own Plugin Name Description: What your plugin does Version: 0.1 License: GPL Author: Brendan Cornelius Author URI: http://br3nd4nc.blogspot.com */ ?> You can add your own PHP code in this file and upload to the "plugins" folder on your server via FTP Once you upload your file go to your plugins section in your Wordpress Dashboard and activate the plugin

How to Add your own shortcode in Wordpress

In your "functions.php" file in your child theme folder create a function and use the following code to initiate the short code add_shortcode('credits', 'show_website_credits'); The first variable above is the shortcode itself ( in this case [credits]) and the second variable is the name of the function. In total it will look like this function show_website_credits() {   return "Website developed by Brendan."; } add_shortcode('credits', 'show_website_credits');

Add cc email address to Contact Form 7 in Wordpress

Simply add this line under the "Additional Settings" field in your Contact Form 7 settings Cc:you@yourdomain.com