Skip to content

Instantly share code, notes, and snippets.

View thagxt's full-sized avatar
🎯
Focusing

ʞↃ∀ɾ thagxt

🎯
Focusing
View GitHub Profile

Regular expressions syntax

Regular Expression Matches
foo The string “foo”
^foo “foo” at the start of a string
foo$ “foo” at the end of a string
^foo$ “foo” when it is alone on a string
[abc] a, b, or c
[a-z] Any lowercase letter
@thagxt
thagxt / home.php
Created March 23, 2016 21:10
Limit WordPress' the_excerpt to the first full stop / period
<?php
// Limit WordPress' the_excerpt to the first full stop / period
$strings = preg_split('/(\.|!|\?)\s/', strip_tags($post->post_content), 2, PREG_SPLIT_DELIM_CAPTURE);
$excerpt = apply_filters('the_excerpt', $strings[0] . $strings[1]);
echo $excerpt;
?>
@thagxt
thagxt / login.php
Created February 18, 2016 17:11
simple PHP login without a database
<?php
session_start();
// ***************************************** //
// ********** DECLARE VARIABLES ********** //
// ***************************************** //
$username = 'username';
$password = 'password';
@thagxt
thagxt / recently-updated-feed.php
Last active June 28, 2017 21:05
Custom RSS feed for WordPress with the latest updated posts.
<?php
/**
* Template Name: RSS - Recently Updated
*/
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'modified',
'order' => 'DESC',
@thagxt
thagxt / functions.php
Created January 27, 2016 14:22
Function to add a class to all your "POST" images in WordPress and get them ready for lazyload.
<?php
function lazyload_filter_content($content) {
global $post; // getting The whole post objects
$content = $post->post_content;
if( is_singular() && is_main_query() ) {
//Renaming images for lazy loader!!!
@thagxt
thagxt / single.php
Created December 18, 2015 15:25
Get All images attached to post & their image title, caption, description
<?php
/*
Getting all images attached to current post
+ getting the IMAGEs: alt, title, caption, description, url defined in Library for every image.
Place this script inside the loop.
*/
$args = array(
'post_type' => 'attachment',
@thagxt
thagxt / csv-as-html-table.php
Created October 28, 2015 15:49
Display CSV file as HTML Table with first 2 columns clickable
<?php
$file = "releases.csv"; // your csv file name
$directory = $_SERVER['DOCUMENT_ROOT']."/var/releases/".$file; // path to file
$row = 1; // horizontal
if (($handle = fopen($directory, "r")) !== FALSE) {
echo '<table id="releases-calendar">';
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { // change ";" if your csv delimiter is different...
@thagxt
thagxt / functions.php
Created October 15, 2015 21:02
Display WordPress' featured image in RSS feed
<?php
function FeatToRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'large', array( 'style' => 'max-width: 300px;' ) ) . '' . $content;
}
return $content;
}

Forcing HTTPS Redirection and Cloudflare’s Flexible SSL

If you force http to https redirection on your website, while using CloudFlare, with the following normal methods, a loop redirection occurs.

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Normal Redirect via PHP

@thagxt
thagxt / check-if-valid-url.php
Last active March 20, 2024 08:00
check if url is valid
<?php
/* @ http://stackoverflow.com/a/12628971 */
function isValidUrl($url){
// first do some quick sanity checks:
if(!$url || !is_string($url)){
return false;
}
// quick check url is roughly a valid http request: ( http://blah/... )
if( ! preg_match('/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i', $url) ){
return false;