Skip to content

Instantly share code, notes, and snippets.

alwerner alwerner

Block or report user

Report or block alwerner

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Get Wordpress custom page content
<?php $page_contents = get_post();
// use print_r if you want to see everything in the array
// print_r($page_contents);
$page_data = $page_contents->post_content; ?>
<div><?php echo $page_data ?></div>
View deferred script loading
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "{{site.url}}/js/deferred.min.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
View measure execution with performance.now();
var t0 = performance.now();
doSomething();
var t1 = performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.")
View Force file download via htaccess
// in .htaccess
<FilesMatch "\.(mov|mp3|mp4|wav|pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
View Convert Sublime Text indentation
Go to:
View -> Indentation
It should read:
Indent using spaces [x]
Tab width: 2
Select: Convert Indentation to Tabs
View sequential loading container with multiple images inside
// using imagesloaded to sequentially load a target containing multiple images
// http://imagesloaded.desandro.com
(function shownext(target){
target.eq(0).imagesLoaded().done(function() {
$(target.eq(0)).fadeTo(150, 1, function() {
target = target.slice(1);
View rename git branch locally then at origin
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
View Wordpress sitemap.xml in functions.php
add_action("publish_post", "eg_create_sitemap");
add_action("publish_page", "eg_create_sitemap");
function eg_create_sitemap() {
$postsForSitemap = get_posts(array(
'numberposts' => -1,
'orderby' => 'modified',
'post_type' => array('post','page'),
'order' => 'DESC'
));
View Use Wordpress get_page_by_title to extract page data from CPT
<?php $page_id = get_page_by_title($page->page_title);
$page_data = get_page($page_id); ?>
<p><?php echo $page_data->post_content; ?></p>
You can’t perform that action at this time.