Skip to content

Instantly share code, notes, and snippets.

Avatar

Jay Versluis versluis

View GitHub Profile
@versluis
versluis / yearsmarried.php
Last active Sep 6, 2020
Calculates how many years I've been married to Julia :-)
View yearsmarried.php
<?php
function guru_yearsmarried() {
// dates to be calculated
$dateMarried = strtotime( '2004-04-22 15:00:00' );
$currentDate = strtotime( current_time ( 'mysql' ));
// calculate the time in seconds and convert
$seconds = $currentDate - $dateMarried;
$years = $seconds / 60 / 60 / 24 / 365.242199;
@versluis
versluis / is_blog.php
Last active Sep 4, 2020 — forked from wesbos/is_blog.php
WordPress is_blog()
View is_blog.php
<?php
function guru_is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
}
if (guru_is_blog()) { echo 'You are on a blog page'; }
@versluis
versluis / shortcodes.php
Last active Sep 3, 2020
Creating basic Shortcodes in WordPress
View shortcodes.php
<?php
// create your shortcode function
function guru_my_shortcode() {
// do something here
// return text you want to display
return $output;
}
@versluis
versluis / latest-youtube-video.php
Last active Sep 3, 2020
Pull in the latest video from YouTube
View latest-youtube-video.php
<div class="iframe-container">
<iframe class="latestVideoEmbed" vnum="0" cid="UCMhv8E4GMw6erC-9iiYtNFg" allowfullscreen="" width="800" height="480" frameborder="0"></iframe>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
var reqURL = "https://api.rss2json.com/v1/api.json?rss_url=" + encodeURIComponent("https://www.youtube.com/feeds/videos.xml?channel_id=");
function loadVideo(iframe) {
$.getJSON(reqURL + iframe.getAttribute('cid'),
function(data) {
var videoNumber = (iframe.getAttribute('vnum') ? Number(iframe.getAttribute('vnum')) : 0);
console.log(videoNumber);
@versluis
versluis / WordPress-Login-Logo.php
Last active Aug 26, 2020
Changing your WordPress Login Logo
View WordPress-Login-Logo.php
// add my own Login Logo
function guru_login_logo() { ?>
<style type="text/css">
#login h1 a, .login h1 a {
background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/images/your-logo.png);
height:65px;
width:320px;
background-size: 320px 65px;
background-repeat: no-repeat;
padding-bottom: 10px;
@versluis
versluis / category.php
Last active Nov 15, 2019
How to extract the Category Title without a URL
View category.php
// print the categry title without a link
foreach((get_the_category()) as $category){
echo '<h1 class="page-title">' . $category->name . '</h1>';
}
// print the category description
the_archive_description('<blockquote class="wp-block-quote">', '</blockquote>');
@versluis
versluis / functions.php
Created Aug 14, 2019
make Gutenberg Galleries link to Media File by default
View functions.php
// make galleries link to Media File
// https://wordpress.stackexchange.com/questions/115368/overide-gallery-default-link-to-settings
function make_galleries_link_to_file() {
$post_type_object = get_post_type_object( 'post' );
$post_type_object->template = array(
array( 'core/gallery', array(
'linkTo' => 'media',
) ),
);
}
@versluis
versluis / functions.php
Created Jul 25, 2019
adds file upload capabilities to the Contributor Role in WordPress
View functions.php
// add file uploads to Contributor role
function add_uploads_to_contribs () {
global $pagenow;
// grab contribtor role
$role = get_role ('contributor');
// if this theme is activated, add the upload capability
if ('themes.php' == $pagenow && isset ($_GET['activated'])) {
$role -> add_cap ('upload_files');
@versluis
versluis / yum history undo
Created Jul 12, 2019
yum history undo - Dependencies Resolved
View yum history undo
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
php-mysql i686 5.4.45-56.el6.art atomic 461 k
Removing:
gd-last i686 2.2.5-5.el6.remi @remi-safe 372 k
libargon2 i686 20161029-7.el6.remi @remi-safe 58 k
View yum history
yum history
Loaded plugins: fastestmirror, refresh-packagekit
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
86 | root <root> | 2019-07-12 11:13 | I, O, U | 11 EE
85 | root <root> | 2019-07-12 11:09 | Install | 1
84 | root <root> | 2019-07-12 10:43 | E, I, U | 19 EE
83 | root <root> | 2019-05-06 08:59 | E, I, U | 27 EE
82 | root <root> | 2018-12-19 22:41 | Update | 2
You can’t perform that action at this time.