Search
add a youtube video preloader function, lazy load youtube [fixed]

I noticed that this list page: https://kruxor.com/list/rs3_efficient_skill/ Loads about 29 (well exactly 29) youtube video embeds and was wondering if there was an easy way to replace these iframes w..
explode a string into an array

This uses the php explode function to split a string into an array based on a delimiter character. I always forget which order this goes in.
checking the current url and then marking a link active based on that url

i want a script that can check the current page uri and then match it to a list of links to be able to add an active class that survives page reloading So here we go... 1. Get the current page url. ..
using gzdeflate on a string php

yes you can actually run compression on a string to save space and then uncompress it at the other end...
linking search results to view pages [finished] 🤣

I was thinking it might be useful to link the search term to the page, so that it can be found more easily using that search. For example, Link this search text (somehow) to the post page and display..
make labels or badges look better

How to make these look better. The labels are used in the list items to show a small version of the category or sometimes the view count for a list item. How they look currently Dark Mode Ligh..
include tinymce only if a user is logged into the site

For google page speed i had an issue when every page was loading tinymce, which is quite a large script. I only actually use this script when editing pages, so this is the change i made to only inser..
adding pagination to custom wp_query

you can add this to your custom wp_query making sure your query also has the paging passed through to it
add paging to wp list query

this is a raw template with list query for specific category names and also includes paging, if the post number is greater than 8 posts in the included categories.
list items from blog and filter by category name

this is a bit raw, but shows the $args = array('category_name' => 'Categy Name 1','Categy Name 2','Categy Name 3' => 8, 'paged' => $paged ); for querying the category_name to do multiple pro..
Quick tool to convert time into decimal

I needed a quick tool that can convert say 20 minutes into decimal, as im doing this a lot these days. Here is what i come up with, well you can google it as well and that works, but this form is a bi..
match a category id in wordpress and then add styles just for that id

this is in template-parts/content.php which may be different based on your theme or version of wordpress. you can locate the category id in wordpress by going into categories and then clicking ..
generating all css colours with php?

I was looking at doing this just to generate all css colours, i think the only issue is there is a lot! You can do this with rgb(0,0,0) all the way up to rgb(255,255,255) how many seperate colours is..
php countries array to dropdown form element

here we generate a form dropdown from a php countries array using the country code as the name of the form option
get the current post id from content.php

this should assign the current wordpress post id to $post_id, from template-parts/content.php if you want to show it, just echo the $post_id
search a zip file with windows command prompt and 7zip

if you ever need to search for a file in a zip file this is how to do it (in windows). Also you will need to install 7zip Open a command prompt CTRL+R and type cmd cd C:\Program Files\7-Zip 7z l c..
Fix for Fatal error: Uncaught Error: Call to undefined function file_get_dom() simplehtmldom simple_html_dom

This error is caused due to a function name change in the simple_html_dom.php library if you are using an older one and upgrading to the never version, you can see it in the change log here: https://s..
Fixing PHP SQLite database is locked warning - Unable to execute statement: database is locked

Apparently this error is caused by not closing the database after using it. Warning: SQLite3::query(): Unable to execute statement: database is locked. You can close the database using the fol..
simple usage for php password_hash

password_hash is used to generate a hash for a password. using this in its simple form can be good for generating a hash from some text like the following code.
What is Core?

17 Aug 20 core is php content management system where the content is editable from the front end of the site, so there is no real back end to this system. i designed it to be easily extended so every..
change string to capital words ucwords

This will change an upper case or lower case, or mixed case string to uc words. Example with this page title
change upper case case string to lower case (uppercase, lowercase)

this can change a lower case or any case into upper case using the str to upper php function Example
convert a string to uppercase with php

use this function to convert a lower case or sentence case string into its uppercase form
php substr return part of a string

good if you want to .. return part of a string
php countries array

country codes to country names array in php
loading content into fancybox modal using ajax

This loads content into a fancybox modal using an ajax request so you can specify a url to load into the modal when the button is clicked
javascript isset equivalent

i was just looking for an equivalent to the isset in php for javascript, i was initially using .length but this can still cause errors so i found this solution. if (typeof my_var !== 'undefined') {}
check if a timestamp is older than one hour

this will check if the timestamp string is less or more than one hour old.
Add a post date to your custom wordpress post listing

this is an example using: get_the_date: this one gets the post date the_excerpt: which gets the .. excerpt or summary text from the post and get_the_post_thumbnail_url which gets the image from th..
making var_dump look nice

i was var_dumping an array the other day, and it comes out like a massive string you cant read. a fast way to make this readable is just to add some pre tags to it.
Nginx Server Block with Rewrite

Nginx Server Block with Rewrite Here is a basic nginx server block with rewrite to the index.php file. So it takes all the parameters and passes them into the index, into the variable $p or $_GE..
pulsating dots - glow glowing

a column of pulsing dots using css keyframes animation
load a youtube video in a fancybox modal

With just a couple of lines of js and html you can load your video links in a modal lightbox. Get the latest version of the fancybox scripts (just the links) from here: https://cdnjs.com/libraries/fa..
using css linear gradient for background overlays

a few examples using css linear gradient for the background
wordpress get page content to display on template page

gets the page content and displays it on a template, this must use the post loop as shown in the code.
ES6 Nested Object Example

extracting variables from a nested object with new variable names
ES5 vs ES6 Object Example

here you can see the syntax changes between ES5 vs ES6 Object declaration, you can still access the values in the same way.
Use Recursion to Return a Range Array

using recursion to return a range array between the two numbers added
Use Recursion to Count Down

just a slight change to the count up version of this, using unshift rather than push to the array.
Get the documentURI with JS

This function gets the current document URI assigns it to the variable documentURI so it can be reused and shows it in the result area once you click on run function.
jquery document ready with foundation init as well

here is a jquery document ready that also loads the foundation js library. im not sure if the document foundation needs to be loaded in the document ready, but this way seems to work.
center something with css not using flex

This is how you can center something in another element if you dont want to use the flex method. You will need the relative position on the outer element, and the absolute on the center one unl..
php mysql table exists function

this checks if a mysql table already exists in the selected database and returns true or false
how to display a php file as html with php

you can use the following function to show a php source file as html
jquery add a click function if the window size is greater than target_width

this function will add a click event to the target if the window size is greater than the target_width
js using recursion to create a range of numbers

in this we will create a function that calls its self to add to an array a range of numbers
php convert date now into a sql timestamp

an easy way to get the current date from php into a mysql or sql timestamp format, this uses the server time
add google captcha to enable and disable a form button

This will check if the google checkbox is checked and then enable or disable the form button depending on the outcome. This is just a basic version of this check, you should also check that the captu..
Generate a Random User Name

a function that will generate a random user name from a list of user names
Using Node to get a Web Dev Environment with livereload up and running

this is how i get a live reloading dev environment up and running on my windows pc's using node , npm and browsersync.
Using the Spread Operator to Evaluate Arrays In-Place Tests

My tests using the Spread Operator rather than the apply function. In the 1st function show_max_array i use the apply operator to convert the array into comma seperated values. In the show_max_array..
Using the rest operator to pass in a variable amount of arguments

If you don't know how many parameters you will need in your function you can use the rest operator to pass them in. ...
Default Parameters for Functions

You can pass in default parameters for functions so that if the function is used with no parameter it will use the default one.
Complex Arrow Function Example

Here is an example using a Complex or Higher Order arrow function, which slightly reduces the amount of code lines used. This should return the square root of all positive integers passed into it.
Writing Arrow Functions with Parameters

you can pass parameters to arrow functions as well as shown in the following demo, these functions are only meant to be used once where normal functions can be re-used.
using arrow functions to convert small functions into one line statement functions

in this exercise i will take a function variable and write it in one line using the arrow function
Prevent Object Mutation

This shows how you can lock an object so its content cannot be modified. if you comment out the line Object.freeze(my_object); it will allow it to be modified again.
Changing an array declared with const

a const means that you cannot re-declare the variable name, but you can still mutate an array content that is declared as a const. so you can see in the following example that even though the array is..
return a state name from an australian postcode

this will return an australian state code based on the postcode, so you can enter a valid postcode and see which state it belongs too. e.g: 2000 should return NSW
using let and const example

This example uses let and const rather than just vars, let can only be declaired once rather than overwritten like vars and const is a read only variable so it cant be changed.
using let rather than var

Using let rather than var and use strict can avoid some overwriting of variables i will write a function here that shows how let throws an error. This function now gives an error in the console. Uncau..
Use Multiple Conditional (Ternary) Operators

I actually find if then statements much easier to read than these ones, but these seem more efficient.
js - Use the Conditional (Ternary) Operator

this statement can be used instead of if this else that statements. to me it makes it look a bit more complex when reading it. this is the basic syntax. condition ? statement-if-true : statement-if-fa..
Use the parseInt Function with a Radix

This is the same as the parseint function, but you can also specify a base for the number which can be between 2 - 36. 2 is binary. Zeros and Ones. I think base 10 is the normal numbering system, but ..
Using parseInt in a function to return an integer or not

this function uses the parseInt function to return a proper integer or an error code if it can't. So this demo should return NaN for the Not an Int (x1235) and The int for the 00001235. I think that N..
Generate Random Whole Numbers within a Range

My testing for generating a random whole number within a range... 🤞 While the solution here works, it just loops until it gets a random number that is lower than the max, so not sure if this is th..
split a string into an array using split javascript

this will split the string into an array based on the spaces inbetween words. you can split it based on any character, for example if you had words in csv comma format you could use the second example..
get the current url in javascript

this will get the current address add it to a variable and show it on the result element
Custom 12 Grid using CSS Grid

For a while i have been using frameworks for their easy grid systems, like foundation and bootstrap. I guess this is a bit lazy and very bloated as you are loading the full css library and using about..
template for testing and live reloading html files

this is a template that i use while testing flat html files, if you add it to a server it will live reload. this does seem to cause issues depending on the site that is is used on, like reloading all ..
Radial Click Effect

shows the radial click effect like in the material design, so when you click a button it will show a click at that area with a nice animation. Uses CSS and javascript to generate this effect.
Generate Random Whole Numbers with JavaScript Function

generate a random whole number function with test buttons
Generate Random Fractions with JavaScript

generate a random fraction and add it to result when clicking a button
FCC - Basic: Profile Lookup

my solution to the FCC Basic js Profile Lookup, with added results area and button to run the function.
copy a file when the date of the source is newer than the destination

using xcopy and a loop i found this is a good way to make sure that changes in one file make their way across to another location using a windows batch file. this one loops every 5 seconds, i think yo..
Do While Loop

showing how to use a do while loop, i don't use these ones very often usually just a for loop.
get the average of a number list using an array in php

get the average of a array of numbers
get the dimensions of an image with javascript

this will show the height and width of an image using javascript
toggle div function with chevron up down toggle

showing an example of chevron toggles kinda like a manual accordion
form checkbox replacement with large tick using label

this is good if you want to change a form checkbox with the default and show a fancy tick or something else, this will still check the checkbox so will work normally as the form element
apache redirect to https ssl from normal

good if you have apache and access to htaccess file to redirect requests to https version of the site. this one also includes a rewrite to index.php so if you don't need this remove the last line.
IP Address

this uses php $_SERVER['REMOTE_ADDR'] to show your IP address
js function to calculate golf scores

this function will return the score name depending on the par and strokes for golf
compare non equality function

this will check if two values are not equal
compare equality function

this will check if two values are exactly equal
testing equality

showing the difference between == and === operators
PHP Finding the position of a string in another string using strpos

$dot_location = strpos($my_string,"."); The first version of this does not seem to work in all cases, so i have updated this with a working version here.
PHP str_replace - find and replace part of a string

basic usage for the str_replace php function str_replace ( mixed $search , mixed $replace , mixed $subject)
Random string generator function in php suniqid

Here is a a smaller version of the built in php function uniqid() uses letters and numbers and specify the length of the random string.
using the disk free space function in php

here is a built in php function that will show the amount of free space available on your server.
create a mysql or sqlite current timestamp with php

just in case you need to create a CURRENT_TIMESTAMP using php, this formats the current date into the following.
Cut a string when it finds a certain character with PHP

ok so lets say we have a string like this: Hi there im a string. I am also part of the same string. And we want to shorten the above string into just: Hi there im a string. This is what i wo..
validate a url using php with FILTER_VALIDATE_URL

checks if a url is valid
function to create a uid from html

this function converts a html string into a uid or unique id type string, its not actually unique, but its a string that can be used to make the title of something that contains html into a usable str..
calculate a percentage (dec) difference based on two numbers

this function will show you the percentage difference between two numbers
PHP MySQL vs SQLite Count Items Function

I have been writing a few functions using sqlite and mysql. There are a couple of slight differences which can be seen in this count items_function.
How Many Days Since a Date and other Calculations

Here i calculate the number of days since a certain date in php and use the values for checking how much something costs per day. Start Date Lets add the date that the item was purchaced. In d..
Date Conversion PHP

Convert 1/1/2011 into 2011-01-01 00:00:00
Generate a random title from an array

give this an array of strings and it will pick a random one to return from the array.
echo todays date and time in a nice format

This will produce some thing like this: 19 December 2018 @ 10:12
Core - File Structure

Core works on the following directory structure: //class//class/extends//css//db//images//import//inc//lib//pages//templates/ all of the core structure is fairly self explanitory core.class.php can..
page load timer class

usage: $page_timer = new page_timer; // at the start of your code echo $page_timer->end(); // at the end of your code.
human_filesize php

function via here http://php.net/manual/en/function.filesize.php#106569
for loop set variables $p1,$p2.. etc as blank

this will loop through and assign the variable $p1 = ""; to each in the loop
sqlite check table name exists

check that the table name exists in a sqlite database, this function it taken from a class.
get current class name with get_class

This will return the current class name, can be used in side a function of the current class object or give it another object name to return. class myclass {function myfunction() {echo get_class($thi..
assign array to variables in a loop

this will assign all items in the array to variables $p1,$p2.. etc. $p = "/1/2/3/4/5/"; $page_array = explode("/",$p); foreach ($page_array as $key => $value) { if($value > "") { ${"p".$pc..
generate a random color rgb code with php

this code will generate a random color every time its loaded using the rand function in php and generate something like this. .random-color { color:rgb(111,222,111); } PHP Code <?php ..
Regular expression breakdown regex preg_replace php

/ - opening delimiter (necessary for regular expressions, can be any character that doesn't appear in the regular expression \( - Match an opening parenthesis [^)]+ - Match 1 or more character that..
replace anything in brackets in a string using preg_replace regex php

Lets say we have a string like this hi there im a string (not really a string). and we want to remove this bit (not really a string) We can do this using the following regex (preg_replace) $strin..
for loop with a 5 increment

$css_out = "";$max_width = "50";for($i=0; $i<=$max_width; $i = $i + 5) {$css_out .= ".m".$i."{margin:".$i."px;}";}return $css_out;
Get Current Page URL PHP

There is a few methods of getting this but here is a simple one. Replacing the http or https manually. $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; Here is a more complex ..
Get the document root path in php $_SERVER['DOCUMENT_ROOT']

I ususally use this one if i am linking to files in the server document root folder rather than specifying ../directory/include.file.php i will use something like this: $document_root = $_..
remove all of an element in a string <h1>

good if you want to remove all of the instances of an element in a string like if you have a <h1> tag in your string and want to remove it you can use the following code. $additional = "some te..
get text between tags

Using DOMDocument you can get strings between tags Useful if you are processing raw html files with php function getTextBetweenTags($string, $tagname){ $d = new DOMDocument(); $d->load..
sqlite basic sql and loop results

basic loop through sql results using sqlite and php $sql = "select $field_name from $db_table_name"; $out = ""; $result = $db->query($sql); if($result) { while($row = $result->fetchA..
convert all images into base64 encoded

if you have a bunch of html with inline image links this will convert them into base64 images inline. <?php $html = "my html string with multiple image tags..."; $dom = new DOMD..
wordpress change domain in config

When moving wordpress sites around the place its usually easiest to change the domain like this. add these to your wp-config.php file define('WP_HOME','http://newsite.com'); define('WP_SITEURL','ht..
read and sort directory contents in php

if you need to read in the contents of a directory in php and sort it by date header('Content-Type: application/json'); $dir = "./html/"; $file_type = ".html"; $out = ""; $files_array[] = ""; ..
uniqid random string

Here is a smaller implimentation of the built in uniqid() function. Good if you want to generate smaller unique strings for url's uniqid example suniqid(5) function suniqid($len = 5) { $..
show response headers from file get contents

this will show the http_response_header when using file get contents, can be useful for seeing what the server is doing. $contents = @file_get_contents($url); echo "<pre>"; var_dump($http_re..
wordpress show the page content for use in a template

if you are using page templates in wordpress and need to show content from wordpress this is the easiest method. This only works for wordpress "pages" not blog "posts". For showing blog posts you will..
file get contents reads entire file into a string

you can use the file_get_contents function to read a file or a web address usage get a url content $homepage = file_get_contents('http://www.example.com/'); echo $homepage; get a file con..
using parse_url to extract parts of a url

Category: PHP the parse_url php function will split a url into an array of url fragments $url = "http://kruxor.com/path/?argument=value#anchor"; var_dump(parse_url($url)); parse_url example ..
basic for loop

I know i always forget this so ill add it here, see if i can remember it. This should count to 10 Out 0 1 2 3 4 5 6 7 8 9 10
try catch test

try and catch example try { //enter code to catch file_get_contents($link); } catch(Exception $ex){ //Process the exception $page_content .= "Unable to process : $link"; }
tell wordpress to use the direct file method if its asking for ftp details

this usually happens if the permissions on the wordpress wp-content folder are not correct or writable. check the permissions are correct: (this is for apache, the user names might be different che..
wordpress enqueue slicknav and slick slider

add this to your theme scripts functions file here is the full one from HTML5 Blank // Load HTML5 Blank scripts (header.php) function html5blank_header_scripts() { if ($GLOBALS['pagenow'] != ..
wordpress include jquery in theme functions

Add this to your themes functions.php file, to include your own version of jquery. if (!is_admin()) add_action("wp_enqueue_scripts", "jquery_enqueue", 11); function jquery_enqueue() { wp_deregi..
copy file

The copy() function copies a file. This function returns TRUE on success and FALSE on failure. echo copy("source.txt","target.txt");
some date formatting just day just month just year

Useful if you need to get PHP to return parts of the date. The date today in number format $date_today = date("d"); e.g: 21 Todays month name $month_name = date("F"); e.g: July ..
header type json

Changes the header to show json type content when the server requests it. header('Content-Type: application/json');
wordpress use a shortcode in php gravity forms

good for using shortcodes in your wordpress templates
extract meta tags from url and return as json array

this will download the url and extract its meta tags returning a json encoded string, with json headers. If the url is accessable. <?php header('Content-Type: application/json'); if(!isset($..
csv read example

Not sure if this is the best or correct way of handling CSV file imports, but it worked for me. here is an example of opening a csv and importing the content into a class, you will need to create ..
php get the file modified time with filemtime

Good for reading the modified time of files with php... echo date("F d Y H:i:s.",filemtime("html/php-get-the-file-modified-time-with-filemtime.html")); will output
preg_replace ereg_replace replace all chars

This will replace all characters that are not A-Z a-z 0-9 and - $uid = preg_replace("/[^A-Za-z0-9\-]/", '', $uid);
wordpress check home and not home for banners and things

this quick function will check if the page is home or not good if you want something on the other pages and something just on the home page in the header or that kind of thing. i have tested this i..
using custom request headers array with curl

this function passes in an array with custom request headers to curl, good if you need to pass in some headers to request an api url and give it an auth key or something like that. Also added to the a..
sqlite delete data older than timestamp days

good if you need to delete data older than a certain date, i tested this and it seems to delete data older than 2 days but might have had the time stamp incorrect or something. DELETE FROM $db_tabl..
wordpress get site url

good for using in templates in case the site is moved <?php echo get_site_url(); ?> Usage Example (css) using inline styles in a template file <style> .class { background:url("<?p..
simple html dom extract attributes simplehtmldom

this is if you have an element as follows, and you want to extract attributes from it. <img class="an-image-wow" src="image.jpg" data-image="data-image.jpg" alt="my alt tag"> list all its ..
find the 1st occurence of a string in another string

do a case-sensitive search for a string within another string strpos mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) usage find the 1st location of a string position within a..
pretty printing json with php

nice if you are working with json string data and just want to be able to read through the structure without copy pasting it somewhere else. $json_string = json_encode($data, JSON_PRETTY_PRINT);
extract meta tags from file or url as array

php has a built in function that can be used to extract the meta tags from a page url into an array. usage just pass it a url, if you call this file meta.php. usage: meta.php?url=http://my-url.co..
wordpress show posts loop with feature image thumbnail

this is surprisingly hard to find code that lists all blog posts in a template with the feature image that does not use an additional plugin. you shouldnt need a plugin to do this as its already built..
random number using rand

Show me a random number between 6 and 12 echo $number = rand(6,12);
search within files in a directory

During my quest to create a semi-static site that is searchable and fast to load. I thought while loading all of this content in with ajax and such that it would be interesting if i could do a text ..
wordpress show the post content for use in a template

if you are looking to show the page content in a template you can find that here. This will show all posts in the selected category Modified source from here
show errors in php with toggle

Toggle showing errors in php if your server is configured not to show them, good for testing. If you dont have this enabled it will usually just show a 500 error with no details of where the error o..
count the elements in an array

seems easy, if you need to know the amount of elements in an array this is how you do it. good if you need to know where the end of an array is. code <pre> <?php $array = [ "yo", ..
parallax js scroll testing

Update: the demo on this one seems a bit broken, i have to fix it! :) you can view a working demo here: https://codepen.io/kruxor/pen/PpGLRG This is one that i had a demo of on codepen, and then code..
jquery clone and append elements

This jquery function clones an element and appends it to another one. Here is the basic code: $( ".clone-me" ).clone().appendTo( ".append-me" );I also updated this to work with just raw js, so..
truncate text long titles with text overflow ellipsis

this one can be useful for fitting text into smaller places without it looking broken. text-overflow: ellipsis; this basically adds the 3 dots where the end of the text used to be... Also if you are ..
margin padding framework

Just a quick margin and padding framework that i came up with, to make margins padding and basic styles a bit quicker.
wordpress get template directory

Get the current theme directory, good for use in wordpress templates. <?php echo get_template_directory_uri(); ?> Usage Example To link to an image located in the theme directory <..
check the server method post or get using php

Here is a basic usage method for checking if the server is in post or get mode. most normal pages are served in get mode. You can send data back to a page using get by adding variables to the string ..