Skip to content

Instantly share code, notes, and snippets.

View Nodws's full-sized avatar

James Nodws Nodws

View GitHub Profile
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
@Nodws
Nodws / Add prefix or suffix
Last active July 18, 2019 16:39
Find-Replace string in file's name
#add prefix
rename s/'^'/'MyPrefix'/ *
#add suffix
rename s/'$'/'MySuffix'/ *
#numbered
n=1; for f in ./*.jpg; do mv "$f" $n.jpg; n=$((n+1)); done
setInterval(function() {
$("#refresh").load(location.href+" #refresh>*","");
}, 10000); // milliseconds to wait
@Nodws
Nodws / .htaccess
Last active January 17, 2023 06:45
Htaccess snips
#<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<ifModule mod_headers.c>
Header always set Content-Security-Policy "upgrade-insecure-requests;"
Header set Access-Control-Allow-Origin "*"
</IfModule>
<FilesMatch "^(wp-config|wp-settings|wp-trackback|wp-comments-post|xmlrpc)\.php$">
Order allow,deny
Deny from all
@Nodws
Nodws / WPConfig.php
Last active October 21, 2023 16:47
home and theme dirs
<?php
define('td', get_bloginfo('template_directory').'/' );
define('hd', esc_url(home_url( '/' )));
//WPconfig
$path = ''; //No trail
$http = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
define( 'WP_SITEURL', $http . $_SERVER['SERVER_NAME'] . $path );
define( 'WP_HOME', $http . $_SERVER['HTTP_HOST'] . $path );
@Nodws
Nodws / Breadcrumbs.php
Last active March 19, 2024 17:32
Get meta
<?php
//FOR POST
$t = wp_get_post_terms(get_the_id(),'taxonomy');
$t[0] = ($t[0]->parent && !$t[1]->parent) ? $t[0] : $t[1];
if($t[0]->parent)
{ $p = get_term_by('id',$t[0]->parent,'taxonomy');
echo '<a href="'.get_term_link($t[0]->parent,'taxonomy').'">'.$p->name.'</a> &raquo; '; }
echo '<a href="'.get_term_link($t[0]->term_id,'taxonomy').'" class="crumb-current">'.$t[0]->name.'</a>';
//FOR ARCHIVE
<?php
$cache = 'data.txt';
if(date("Ymd", filemtime($cache)) < date("Ymd") || filesize($cache) < 1):
$data = get_data(); // do your thing
$file = fopen($cache,'w+');
$text = is_array($data) ? json_encode($data) : $data;
fwrite($file, $text);
fclose($file);
else:
$file = fopen($cache,'w+');
<?php
//remove accents
setlocale(LC_ALL, "en_US.utf8");
function clean($txt){
$txt= iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $txt);
$re = "/[^\\w.-]/";
return preg_replace($re, "", $txt);
}