codehaven - php snippets - coding help
Generic filters
Exact matches only

Import csv to phpmyadmin

mysql codehaven category

Updated 29/01/2021 Simple but can cause lots of problems. I have one column with 200,000 postcode entries! in a CSV file. One Tab. Like below My first insert of 4000 was quick without error, but the 200,000 had import errors. I tried many Free CSV splitters online but all had problems except one! https://textfilesplitter.com/ So […]

Create a plugin with shortcode for Elementor – Most basic ever!

wordpress category

1. Save this code below as rawcode.php

2. Create a folder in the plugins folder called the same – “rawcode” (\wp-content\plugins\rawcode) 3. This will now show up as a plugin. Activate it. 4. In a page or post within elementor (or without) add the following shortcode. [rawcode-plugin-demo] 5. It will now appear in the […]

Add a dropdown to Woocommerce Checkout Fields

woocommerce category codehaven

To add a dropdown or select element to the fields on a woocommerce checkout, this can be achieved by the following code. Just add this code and amend where necessary to the functions.php file. Add dropdown

Update dropdown

Display dropdown answer

Change height of category quick edit box in Dashboard

woocommerce category codehaven

To change the height of the quick edit category box add this code toy your functions.php page. It will add the CSS as the last command and you then can change the height instead of scrolling all day.

Align ‘Add to Cart’ product buttons – WooCommerce

woocommerce category codehaven

This problem should be sorted by Woocommerce but they still have the problem. when you have to redesign a website that has weird image sizes and you cant really do much about that, you need to find a way to align all the buttons so they look neat. The only way I have found that […]

Award for the Worst Unsubscribe page 2021

codehaven code snippet review

Update 15/1/21: We have had to take back the award as they have updated there unsubscribe page! (I am pretty sure they will be OK about that!). This shows they respond to emails in a positive manner and the chain of command in a complaint gets to the correct people. Well done Rated People.There updated […]

How to find the last folder in url

php codehaven

If this is my url I am running the script in http://aq.gthex.co.uk:10000/webcontent/mylogin.php and I want to find the part called webcontent use the script below to find this part.

The result will be: webcontent

Convert number to month name in PHP

php codehaven

How to catch errors and warnings in PHP

php codehaven

Catching errors and Warnings Below is a standard for catching errors. This would not work for warnings. That code is at the bottom.

How to catch warnings

Add a Favicon to your website

wordpress category

Add this code below to the header of your website. Then add the favicon (png) to the root of your website.

You can use .ico files by using the code below.

Add this to your header.php file and add the image usually 16px x 16px in your root.

Enable GTmetrix Old Style Reports – December 2020

SEO category

So GTmetrix.com thinks they have helped us, by creating a whole new version of their very good website testing site. Unfortunately they have not. They have just made it more difficult to find the results we are used to! Luckily I have found a switch within their settings that puts it all back the way […]

Free Share Code for Freetrade App

codehaven code snippet review

Buy & Sell Shares for FREE instantly Usually when you buy shares through a bank or building society like Halifax they charge you about £10 every time you buy some shares or sell them!!! Freetrade is free to buy and sell shares! USE THE LINKS BELOW https://magic.freetrade.io/join/mike/e307a29f HOW TO USE Use my link to join […]

How to remove “description” heading in product description? – WooCommerce

woocommerce category codehaven

Woocommerce provides a couple of tabs such as Product Information, and Description. you may find under the tab it repeats which can look weird. to remove the duplicate wording use the code below in the functions file.php

Adding Canonical link manually – PHP

SEO category

if you have a hand coded site to help with your SEO you need a canonical link. Below is a PHP script that creates a canonical url link on page load. So this should answer your question of how to add canonical tag in PHP This is a self-referencing canonical link

Check if PHP array empty

php codehaven

You can also use not empty, by adding an exclamation mark.

Dropdown from MySql Select Query – Select

mysql codehaven category

Creating a dropdown from a MySql query is quite easy There are a few ways, simplest is to create an array then just loop

Another method without an array.

Maybe pull three things…..

And for two dropdowns take a look here.

Auto Resize Dropdown to fit text – Select – Jquery

jquery icon

If you have ever had a dropdown text box that someone has added a very long option to, you will know that it can put your whole page design out. Using this method it the most easiest way. Just add it to your page and it will sort out all your select boxes in one […]

Get last part of url – page name

php codehaven

If you need to get the last part of a url of the page you are in, the code below will show you.

Shows loop.php

Trim left Javascript text

javascript category codehaven

Simple way to trim whitespace for the beginning of text using JavaScript.

Output = “Hi ” To replace all whitespace using Javascript use this next script. http://aq.gthex.co.uk:10000/javascript/trim-whitespace-javascript/

Sweet Alert with textbox edit

jquery icon

After many hours of trying Sweet Alert, I have finally managed to add a textbox, and edit a variable. The magic part was inputValue: keywordid

Another version of this is the text area input with sweet alert This is supposed to be the way of adding text input but I never managed to make […]

Write many Arrays to a Database in one insert

php codehaven

This should really use foreach instead of counting the array, but it could come in handy!

MySQL result as first in PHP Select Dropdown

mysql codehaven category

This will show your result from saved data as the first in a dropdown of other results. On its first loop it will add something in the beginning, then add the rest.

Refer to parent element from within ajax call – Jquery

jquery icon

If you use $(this) within the ajax code it will not find the element you need. Get the element at the beginning using (this) and create a variable of it. Then you can late refer to this variable in the ajax part.

Change Static loading Hourglass icon on Firefox 80

Firefox - Codehaven

Does your Firefox loading icon now look like this? If you have used Firefox lately and your egg time/hourglass icon is now static when loading a web page then this will solve the problem and make it the nice loading animation you had previously. One switch is all you need. (only works for Windows). How […]

Sweet Alert text input and save to a database

jquery icon

The code below will save the input from Sweet Alert and save this to a database. You need to prepare the MySQL saving page (addpage.php) and collect post data ‘pagename’ I have added my sweet alert cdn

Hope this works for you.

Website Shame Awards

codehaven code snippet review

If you are listed here then you need to work just that little bit harder. I can understand when you are doing a website yourself, you don’t have much time to devote to this. If you are one of the biggest companies in the world then maybe you should check your website maybe once or […]

Field “ssl certificate, ssl key” can not be blank.

random coding category codehaven

If you have this error “Field “ssl certificate, ssl key” can not be blank.” then this is how you fix it. open file /usr/local/vesta/data/users/—user_name—/web.conf find “LETSENCRYPT” where you want reload LETSENCRYPT set “no” resave domain

Create a Random Password in Javascript

javascript category codehaven

A simple way to create a random password in JavaScript

How to Share your Google Analytics Account in 6 Steps

wordpress category

Step 1 Open your Google Analytics dashboard, and click the cog Step 2 Click Property User Management Step 3 Click the blue plus icon in top right Step 4 Click Add Users Step 5 and 6 Add the email of the person you wish to access Google Analtytics data, and then click Add

Resize gallery thumbnails to show only 3 – Woocommerce

woocommerce category codehaven

I only have 2 or maybe 3 images per product but the gallery is expecting lots, so it sets out 4 columns, which makes my images very small. Therefore I need to have only 3 columns. The code below lets me set as many columns as I need.

and now it looks like this…

How to Fix Blurry Gallery Thumbnails in Woocommerce

woocommerce category codehaven

I had some really blurry gallery thumbnails in Woocommerce, using the Hello theme with Elementor. The images uploaded were of very high quality and so I read a few blog posts and found out about “Regenerate Thumbnails” plugin. So I thought I would give it a go. I installed then regenerated the thumbnails, and it […]

Change ‘Add to cart’ button to ‘View Product’ in Woocommerce

woocommerce category codehaven

Changing the button text to read ‘View Product’ in Woocommerce In this case I have changed it to “Have a Look”…

How do I add the Widgets menu using “Hello Theme” for Elementor?

wordpress category

To enable the Widgets menu item in the WordPress admin menu, add the following code in your functions.php file

You will then have the Widgets menu available to you, you can then assign Widgets to the Sidebar as usual in Appearance > Widgets. Note: This may cause a warning in WordPress 5.6. My local […]

Upload image with PHP – Simple

php codehaven

testupload.php

target.php

Change default woocommerce myaccount text

woocommerce category codehaven

If you want to change the default myaccount text that shows after login (“From your account dashboard you can view your recent orders etc), then editing the file within the woocommerce plugin will work, but you need to pay special attention to how this is done. If you just edit the file, when woocommerce is […]

Center a heading over an image using Elementor

Css - Codehaven

To centre a heading using elementor can be very difficult, especially when tablet mode and mobile mode are transitioned to as the pixels away from the top and bottom change, therfore the heading moves. If you use a standard image, and underneath that add a heading. Then add the following code the CSS of the […]

Change Woocommerce checkout text – Coupon to Voucher

woocommerce category codehaven

This code fully works, and unlike a few others codes the link to the checkout works. This is a mashup of snippets that works. add this to your functions.php file and it will find the word ‘Coupon’ and change it to ‘Voucher’.

Change ‘shipping’ to ‘delivery’ in Woocommerce

woocommerce category codehaven

To replace the word shipping which is more American to delivery the code below will work for you.

Password strength checker in jQuery

jquery icon