Skip to content

Instantly share code, notes, and snippets.

View sabrina-zeidan's full-sized avatar

Sabrina Zeidan sabrina-zeidan

View GitHub Profile
@sabrina-zeidan
sabrina-zeidan / bulk_delete_revisions.php
Created July 22, 2017 13:58
Bulk delete revisions [Wordpress]
function bulk_delete_revisions(){
$args = array( 'post_type' =>'revision', 'posts_per_page' => -1, 'post_status' => 'any', 'fields' =>'ids');
$revisions = get_posts( $args );
foreach ($revisions as $revision) {
wp_delete_post( $revision, true);
}
}
add_action( 'wp_head', 'bulk_delete_revisions' );
@sabrina-zeidan
sabrina-zeidan / bulk_convert_csv_to_xlsx.vbs
Last active July 22, 2017 14:54
This macros will bulk covert csv to xlsx in Excel. First, save csv to txt (just changing name.csv to name.txt in totalcommaner or similar, bulk in one click). Place to CSVfolder = "C:\csv\txt\" ,output will be here XlsFolder = "C:\csv\xlsx\"
Private Sub CommandButton2_Click()
Dim CSVfolder As String, _
XlsFolder As String, _
fname As String, _
wBook As Workbook
CSVfolder = "C:\csv\txt\"
XlsFolder = "C:\csv\xlsx\"
fname = Dir(CSVfolder & "*.txt")
@sabrina-zeidan
sabrina-zeidan / delete_all_tags.php
Last active July 22, 2017 15:01
Bulk delete all tags [Wordpress]
function delete_all_tags(){
$tags = get_tags( array('number' => 0,'hide_empty' => false));
foreach ( $tags as $tag ) {
wp_delete_term( $tag->term_id, 'post_tag' );
}
}
add_action( 'wp_head', 'delete_all_tags' );
@sabrina-zeidan
sabrina-zeidan / clean_uploads_from_nonattachments.php
Last active July 26, 2017 10:54
This function frees disk space on your hosting account. It will scan your uploads directory (recursevely) and check every found file whether it is wp attachment or no. All files that are not attachments (no matter got parents or no) will de deleted. [Wordpress]
//Delete orphaned files in wp-content/uploads that are not wordpress attachments
function clean_uploads_from_nonattachments(){
$uploads_dir = wp_upload_dir();
$search = $uploads_dir['basedir'];
$replace = $uploads_dir['baseurl'];
//You may want to take it by bites if your uploads is rather large (over 5 gb for example)
//$uploads_dir = ( $uploads_dir['basedir'] . '/2015/' );
$uploads_dir = ( $uploads_dir['basedir']);
$root = $uploads_dir;
//Going through directiry recursevely
@sabrina-zeidan
sabrina-zeidan / filter_images_links_from_post_content.php
Last active July 29, 2017 09:26
Filters images links from post content on page load with the_content filter [Wordpress]
add_filter( 'the_content', 'attachment_image_link_remove_filter' );
function attachment_image_link_remove_filter( $content ) {
$content =
preg_replace(
array('{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}',
'{ wp-image-[0-9]*" /></a>}'),
array('<img','" />'),
$content
);
return $content;
@sabrina-zeidan
sabrina-zeidan / prevent_image_links.php
Created July 29, 2017 09:45
Prevent links around your images on image upload in the content [Wordpress]
@sabrina-zeidan
sabrina-zeidan / limit_post_content.php
Created July 29, 2017 17:36
Limit post character number with the_content filter for guest users [Wordpress]
add_filter("the_content", "limit_post_content");
function limit_post_content($content){
if (!(is_user_logged_in())){
$content = substr($content, 0, 300);
}
return $content;
}
@sabrina-zeidan
sabrina-zeidan / add_multiple_googleads.js
Created October 8, 2017 11:15
jQuery junction for correct inserting multiple Google Adsense blocks on the site. It will generate as many ad pushes as there are GoogleAds blocks on the current page. Automatic, convenient and lean
jQuery(function ($) {
$(".adsbygoogle").each(function () { (adsbygoogle = window.adsbygoogle || []).push({}); })
});
@sabrina-zeidan
sabrina-zeidan / defer_javascript_parsing.php
Created October 12, 2017 17:06
This function will defer parsing of JavaScript for optimized page load [WordPress]
function add_async_and_defer_attribute($tag, $handle) {
//if ( 'adsense' == $handle ) return str_replace( 'src', 'async src', $tag );
//if ( strpos( $tag, 'jquery.js' ) ) return $tag;
return str_replace( 'src', 'defer onload="" src', $tag );
}
add_filter('script_loader_tag', 'add_async_and_defer_attribute', 10, 2);
@sabrina-zeidan
sabrina-zeidan / leave_good_tails.php
Created May 16, 2018 19:20
This function will clean your list of keywords from partially duplicated lines and return just good long-tailed keyword phrases
<?php
/*
* This function will clean your list of keywords from partially duplicated lines and return just good long-tailed keyword phrases
* To learn more about about long-tails in SEO check http://sabrinazeidan.com/long-tail-keywords-for-seo-definition-examples-free-tool/
* Input file format: file.txt, UTF-8 without BOM, one keyword phrase per line
*
*/
function leave_good_tails($txt_file_url) {
$file_headers = @get_headers($txt_file_url);
if ($file_headers[0] == 'HTTP/1.0 404 Not Found'){ // or "HTTP/1.1 404 Not Found" etc.