Skip to content

Instantly share code, notes, and snippets.

name: run-tests
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- master
pull_request:
branches:
@robbens
robbens / functions.php
Created July 5, 2017 16:11
Add "Disallow: *.pdf" in robots.txt programmatically in WordPress
/**
* Disallow pdfs in robots.txt
*/
add_filter( 'robots_txt', function( $output, $public ) {
$output .= "Disallow: *.pdf\n";
return $output;
}, 0, 2 );
@robbens
robbens / functions.php
Last active April 18, 2017 12:37
Small function to get the page set to work as blog in WordPress
<?php
/**
* Gets the blog page set in Settings > Reading.
*/
function rn_get_blog_page_url() {
if ('page' == get_option('show_on_front'))
return get_permalink(get_option('page_for_posts'));
return home_url();
@robbens
robbens / functions.php
Last active April 18, 2017 10:55
Load translations from WordPress child theme
<?php
/**
* Loads the child theme textdomain.
*/
function theme_child_slug_setup() {
load_child_theme_textdomain( 'child-theme-textdomain', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', theme_child_slug_setup' );
@robbens
robbens / main.js
Created April 5, 2017 11:36
Example on how to use Masonry.js with FacetWP
// Init Masonry
var $grid = jQuery('.facetwp-template').masonry({
percentPosition: true,
columnWidth: '.grid-sizer',
itemSelector: '.grid-item'
});
// Reload and update on FacetWP load
jQuery(document).on('facetwp-loaded', function() {
$grid.masonry('reloadItems')
@robbens
robbens / functions.php
Last active April 18, 2017 10:56
Disable WordPress comments on attachment page
<?php
add_filter('comments_open', function ($open, $post_id) {
$post = get_post($post_id);
if ($post->post_type == 'attachment') {
return false;
}
return $open;
}, 10, 2);
@robbens
robbens / functions.php
Last active April 18, 2017 10:56
Download and set image as Featured Image in WordPress.
<?php
// Download and attach image to post.
media_sideload_image($item->image, $post_id, $item->image_caption);
// Then find the last image added to the post attachments.
$attachment = array_values(get_attached_media( 'image', $post_id ))[0];
// Finally set image as the post thumbnail.
if ($attachment) {
@robbens
robbens / default.blade.php
Created January 7, 2017 14:56
Bulma.io pagination for Laravel
@if ($paginator->hasPages())
<nav class="pagination is-centered">
@if ($paginator->onFirstPage())
<span class="pagination-previous is-disabled">Previous</span>
@else
<a class="pagination-previous" href="{{ $paginator->previousPageUrl() }}" rel="prev">Previous</a>
@endif
{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
@robbens
robbens / register.blade.php
Created January 6, 2017 17:58
Bulma.io Register form for the Laravel Auth scaffold
@extends('layouts.app')
@section('content')
<section class="section">
<div class="container">
<div class="column is-half is-offset-one-quarter">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
{{ csrf_field() }}
<p class="control has-icon">
@robbens
robbens / login.blade.php
Last active January 6, 2017 18:00
Bulma.io Login form for the Laravel Auth scaffold
@extends('layouts.app')
@section('content')
<section class="section">
<div class="container">
<div class="column is-half is-offset-one-quarter">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
{{ csrf_field() }}