Skip to content

Instantly share code, notes, and snippets.

View add-thumbnail-to-latest-posts-block.php
function() {
'attributes' => array(
'categories' => array(
'type' => 'string',
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
* 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>
<p>Diese Seite wurde deaktivert.</p>
View .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteRule . /index.html [L]
# END WordPress
View antispambot-shortcode.php
function wpcodex_hide_email_shortcode( $atts , $content = null ) {
if ( ! is_email( $content ) ) {
return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );
View antispambot.php
echo antispambot( '' );
// 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
add_action( 'after_setup_theme', 'theme_start_content' );
function theme_starter_content() {
add_theme_support( 'starter-content', array(
'posts' => array(
'test' => array(
'post_type' => 'page',
View starter-content-add-menus.php
add_action( 'after_setup_theme', 'theme_start_content' );
function theme_starter_content() {
add_theme_support( 'starter-content', array(
'posts' => array(
'test' => array(
'post_type' => 'page',