Skip to content

Instantly share code, notes, and snippets.

@mahdi-alavi
mahdi-alavi / gist:1aceb2a1cc026b60ee0cb8ff0044a584
Created March 6, 2018 06:43
wordpres: Add async Attributes to Enqueue Scripts where Needed
/* Add async Attributes to Enqueue Scripts where Needed.
=========================================================================== */
function itl_script_tag_defer( $tag, $handle ) {
if ( is_admin() ) {
return $tag;
}
if ( strpos($tag, '/wp-includes/js/jquery/jquery') ) {
return $tag;
}
@mahdi-alavi
mahdi-alavi / gist:30b35994013e0c803674ee81d7245d2c
Last active September 29, 2018 09:53
wordpress: Convert string duration to ISO 8601 duration format
/* Convert string duration to ISO 8601 duration format.
=========================================================================== */
function itl_iso8601_duration( $seconds ) {
$hours = floor( $seconds / 3600 );
$seconds = $seconds % 3600;
$minutes = floor( $seconds / 60 );
$seconds = $seconds % 60;
$iso8601 = sprintf( 'PT%s%s%s',
@font-face {
font-family: 'vazir-font';
font-weight: normal;
font-style: normal;
src: url('https://cdn.rawgit.com/rastikerdar/vazir-font/v19.0.0/dist/Vazir.woff') format('woff');
font-display: swap;
}
#board {
padding: 0 15px;
}
@mahdi-alavi
mahdi-alavi / gist:8081f2f322e4cec7aedb69f24cfc0537
Last active October 1, 2018 06:33
Trello RTL style for stylebot
/*
* install stylebot from Chrome Webstore: https://chrome.google.com/extensions/detail/oiaejidbmkiecgbjeifoejpgmdaleoha
* import this style from backup (Stylebot Options)
*/
{{"https://trello.com/b/":{"_enabled":true,"_rules":{"at1":{"at":true,"text":"@font-face {\n \n font-family: 'vazir-font';\n \n font-weight: normal;\n \n font-style: normal;\n src: url('https://cdn.rawgit.com/rastikerdar/vazir-font/v19.0.0/dist/Vazir.woff') format('woff');\n \n font-display: swap;\n}","type":"@font-face"},"#board":{"padding":"0 15px"},"body":{"background":"#216f95"},"body, button, html, input, select, textarea":{"font-family":"'vazir-font', 'Segoe UI', sans-serif","font-size":"16px"},".window-header:after, .window-module-title:after":{"display":"block","content":"''","clear":"both"},"#board, textarea, .checklist-item-row, .card-detail-fake-text-area, .checklist-item-details-text, .phenom.mod-comment-type .phenom-reactions, .phenom-desc, .action-comment p":{"direction":"rtl","text-align":"right"},"pre, code"
@mahdi-alavi
mahdi-alavi / gist:f41ead3ba3b7353a8d5b84a44b873825
Created October 18, 2018 18:09
wordpress: Bootstrap 4.1 pagination
/* Bootstrap pagination.
=========================================================================== */
function itl_paging_nav() {
global $wp_query, $wp_rewrite;
// Setting up default values based on the current URL.
$pagenum_link = html_entity_decode( get_pagenum_link() );
$url_parts = explode( '?', $pagenum_link );
// Get max pages and current page out of the current query, if available.
@mahdi-alavi
mahdi-alavi / gist:13e5022f3c0386e180e2f9f154734bc8
Last active October 30, 2018 19:36
wordpress: custom pagination with wpdb get_results
<?php
global $wpdb;
$sql = "
SELECT $wpdb->posts.*
FROM $wpdb->posts
WHERE $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_date < NOW()