Skip to content

Instantly share code, notes, and snippets.

View add-thumbnail-to-latest-posts-block.php
add_action('init',
function() {
unregister_block_type('core/latest-posts');
register_block_type(
'core/latest-posts',
array(
'attributes' => array(
'categories' => array(
'type' => 'string',
),
@websupporter
websupporter / upload-a-file.MD
Created Jun 15, 2017
Upload a file using the WordPress REST API
View upload-a-file.MD

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

View deactivate-wordpress.php
<?php
/**
* Plugin Name: Deactivate WordPress
* Author: David Remer
* Description: Do use with care. Actually: Do not use!
**/
function deactivate_wordpress() {
remove_action( 'all', 'deactivate_wordpress' );
View index.html
<!doctype html>
<html>
<head>
<title>Deaktiviert</title>
</head>
<body>
<p>Diese Seite wurde deaktivert.</p>
</body>
</html>
View .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteRule . /index.html [L]
</IfModule>
# END WordPress
View antispambot-shortcode.php
<?php
function wpcodex_hide_email_shortcode( $atts , $content = null ) {
if ( ! is_email( $content ) ) {
return;
}
return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
}
add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );
View antispambot.php
<?php
echo antispambot( 'max.mustermann@example.com' );
// Real output: &#109;ax.&#109;&#117;s&#116;erma&#110;&#110;&#64;&#101;&#120;a&#109;&#112;le&#46;&#99;om
?>
View starter-content-add-options.php
<?php
add_action( 'after_setup_theme', 'theme_start_content' );
function theme_starter_content() {
add_theme_support( 'starter-content', array(
'posts' => array(
'home',
'test' => array(
'post_type' => 'page',
View starter-content-add-menus.php
<?php
add_action( 'after_setup_theme', 'theme_start_content' );
function theme_starter_content() {
add_theme_support( 'starter-content', array(
'posts' => array(
'home',
'test' => array(
'post_type' => 'page',