Posts

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