Skip to content

Instantly share code, notes, and snippets.

@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-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_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 / 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);