Archives: Snippets
Default Featured Image
// Go to Settings > Media after activating this snippet to set the default featured image. add_action( ‘admin_init’, function() { register_setting( ‘media’, ‘default_featured_image’, ‘absint’ ); add_settings_field( ‘default_featured_image’, __( ‘Default Featured Image’, ‘wpcode-snippet’ ), function() { wp_enqueue_media(); $image_id = get_option( ‘default_featured_image’,…Continue reading
Inline Spoiler Shortcode
// Hide text using the shortcode like this: [spoiler]hidden text here[/spoiler]. add_shortcode(‘spoiler’, ‘inline_spoiler_shortcode’); function inline_spoiler_shortcode($atts, $content = null) { // Start output buffering ob_start(); // Output the spoiler content with the necessary styles ?>Continue reading
Dynamic Greeting
Special Offer Pop-up
Custom Logo Per Page
add_action(‘add_meta_boxes’, function() { add_meta_box( ‘custom-logo-metabox’, ‘Custom Logo’, function($post) { // Add a nonce field so we can check for it later wp_nonce_field(‘custom_logo_meta_box’, ‘custom_logo_meta_box_nonce’); // Retrieve the existing value from the database $custom_logo_id = get_post_meta($post->ID, ‘_custom_logo_id’, true); $custom_logo_url = $custom_logo_id ?…Continue reading
Google Tag Manager
Code for importing theme files from plugin
/** * Import an entire folder from a plugin into the WordPress theme. * * @param string $plugin_folder Plugin folder path. * @param string $theme_folder Theme folder path. * * @return bool True on success, false on failure. */ function…Continue reading
Add Theme Supports
add_editor_style( ‘style-editor.css’ ); add_theme_support( ‘appearance-tools’ ); add_theme_support( ‘align-wide’ ); add_theme_support( ‘responsive-embeds’ ); add_theme_support( ‘post-formats’, array( ‘aside’, ‘gallery’, ‘link’, ‘image’, ‘quote’, ‘status’, ‘video’, ‘audio’, ‘chat’ ) // WordPress supports the following post formats. These formats cannot be changed by the average…Continue reading
WPCode Functions
// Skip show library screen add_filter( ‘wpcode_add_snippet_show_library’, ‘__return_false’ ); // Move status column add_filter( ‘wpcode_code_snippets_table_columns’, function ( $columns ) { if ( isset( $columns[‘status’] ) ) { $status = $columns[‘status’]; unset( $columns[‘status’] ); $columns = array_slice( $columns, 0, 1, true…Continue reading