List Code
add this
To Add: https://github.com/processing/p5.js/wiki/Loading-external-files:-AJAX,-XML,-JSON
Slick Slider Carousel
Edit: Sorry this page was broken for a bit, its fixed now with working examples! 😛 Nice and simple slider / carousel
change the window title
This is a pretty easy one liner But we can make it a bit more complex with jquery and add a counter It is questionable that crawlers and bots will see this so may be bad for SEO. document.t..
flems embed in url
Flems.io is a single-file, embeddable Web sandbox. It keeps all its state in the URL, so just make your changes, copy the URL from the address bar, and send it wherever you please. Most popular link s..
detect window scroll position jquery
This one adds or removes a class if the document is scrolled 50 px near the top of the window. $(window).scroll(function() { if ($(document).scrollTop() > 50) { $('nav').addClass('shrink');..
truncate string using jquery
.test { padding:10px;border:1px solid #999;border-radius: 3px; } so lets say we had the following string on the page and we needed to make it a bit shorter for some reason. like if you dont have co..
round number with js
Round a number to two decimal places. code var rounded = Math.round(num * 100) / 100; demo Result... function round_val() { var val = $("#rval").val(); var rounded = Math.r..
google map with overlay data
Ever wanted to add a really slightly complex google map to your site? Working Example /* Always set the map height explicitly to define the size of the div * element that con..
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", ..
wordpress register enqueue javascript require jquery
This usually goes in the theme functions file. This will load it after jquery if it requires it. wp_register_script('scriptname', get_template_directory_uri() . '/js/scripts.js', array('jquery'), ..
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..
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
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 ..
random number using rand
Show me a random number between 6 and 12 echo $number = rand(6,12);
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..
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..
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);
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..
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 attr..
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..
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..
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..
wordpress advanced custom fields replace shortcode for site url with blog url
Using advanced custom fields, if you know what the shortcode is and what you want to replace it with you can do so with the following. $site_url = get_site_url(); $field = get_field('template_ht..
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..
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);
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
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 ..
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($..
wordpress use a shortcode in php gravity forms
good for using shortcodes in your wordpress templates
header type json
Changes the header to show json type content when the server requests it. header('Content-Type: application/json');
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 ..
copy file
The copy() function copies a file. This function returns TRUE on success and FALSE on failure. echo copy("source.txt","target.txt");
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..
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'] != ..
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..
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"; }
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
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 ..
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..
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..
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..
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) { $..
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[] = ""; ..
wordpress change domain in config, wordpress domain 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..
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..
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..
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..
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 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 = $_..
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 ..