Skip to content

Instantly share code, notes, and snippets.

@Christian-Roth
Christian-Roth / WP-custom_cron.php
Last active August 26, 2016 11:15
Functions to add a custom WP cron
function your_function(){
// **** Add your function here ****
}
add_action( 'your_cron_action', 'your_function' );
// Init Cron Job
function init_custom_cron() {
if( !wp_next_scheduled( 'your_cron_action' ) ){
wp_schedule_event( time(), '20min', 'your_cron_action' );
}
@Christian-Roth
Christian-Roth / WP-custom_rest_api.php
Last active November 15, 2016 11:39
Functions to add a custom route to the WP REST API
// Init REST Route
function register_custom_api_hooks() {
$namespace = 'custom-name/v1';
register_rest_route( $namespace, '/posts/', array(
'methods' => 'GET',
'callback' => 'custom_api_get_posts',
) );
}
add_action( 'rest_api_init', 'register_custom_api_hooks' );
@Christian-Roth
Christian-Roth / WP-reverse_srcset_order.php
Last active February 18, 2017 10:13
Function to reverse the order in the WP srcset array
function reverse_srcset_order($atts) {
if (isset($atts['srcset'])) {
$srcset = explode(', ', $atts['srcset']);
$srcset_reversed = array_reverse($srcset);
$atts['srcset'] = join(', ', $srcset_reversed);
}
return $atts;
}
add_filter('wp_get_attachment_image_attributes','reverse_srcset_order',1,1);
@Christian-Roth
Christian-Roth / tribe_remove_single_calendar_links.php
Created October 13, 2017 15:30 — forked from elimn/tribe_remove_single_calendar_links.php
MT | TEC | Remove the iCal and Google cal links from the single event page
@Christian-Roth
Christian-Roth / tribe_remove_archive_ical_links.php
Last active October 13, 2017 15:39
The Events Calendar – Remove the iCal and Google cal links from the archive views
@Christian-Roth
Christian-Roth / stars-block.js
Created January 30, 2018 14:53 — forked from pento/stars-block.js
Gutenberg Stars Block
( function( blocks, element ) {
var el = element.createElement;
function Stars( { stars } ) {
return el( 'div', { key: 'stars' },
'★'.repeat( stars ),
( ( stars * 2 ) % 2 ) ? '½' : '' );
}
blocks.registerBlockType( 'stars/stars-block', {
@Christian-Roth
Christian-Roth / WP-cookie-status-shortcode.php
Last active July 8, 2018 09:32
A shortcode to show the cookie status
@Christian-Roth
Christian-Roth / WP-cookies-not-accepted-shortcode.php
Last active July 8, 2018 13:28
A shortcode to show content if cookies are not accepted
<?php /* Shortcode Cookie Not Accepted */
function custom_cn_cookies_not_accepted( $atts, $content = null ) {
if (function_exists('cn_cookies_accepted') && !cn_cookies_accepted()) {
return '<div class="box cookie-box">' . do_shortcode($content) . '</div>';
} else {
return '';
}
}
add_shortcode('cookies_not_accepted', 'custom_cn_cookies_not_accepted');
?>
@Christian-Roth
Christian-Roth / WP-custom_embed_header.php
Last active January 11, 2019 10:21
Function to change the header of WP embeds / Example CSS file
function goyippi_embed_header() {
wp_deregister_style('open-sans');
wp_enqueue_style( 'goyippi-embed-font', 'http://fonts.googleapis.com/css?family=Droid+Sans:400,700','','', 'all' );
wp_enqueue_style( 'goyippi-embed-styles', get_bloginfo('stylesheet_directory').'/wp-style_embed.css','','', 'all' );
}
add_action( 'embed_head', 'goyippi_embed_header' );
@Christian-Roth
Christian-Roth / tribe_get_events_with_ongoing_events.php
Last active August 2, 2019 14:22
The Events Calendar – Show events with ongoing events. More date arguments in /src/Tribe/Query.php, around line 1285.
<?php // Retrieve all events (with ongoing events) in October 2019
$events = tribe_get_events( [
'eventDisplay' => 'custom',
'ends_after' => '2019-10-01 00:01',
'starts_before' => '2019-10-31 23:59',
] );