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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
// ***************************************** // | |
// ********** DECLARE VARIABLES ********** // | |
// ***************************************** // | |
$username = 'username'; | |
$password = 'password'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: RSS - Recently Updated | |
*/ | |
$args = array( | |
'post_type' => 'post', | |
'post_status' => 'publish', | |
'orderby' => 'modified', | |
'order' => 'DESC', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |