Skip to content

Instantly share code, notes, and snippets.

@wecodelaravel
wecodelaravel / wp-excerpt-char-count.php
Created May 7, 2019 01:31 — forked from hearvox/wp-excerpt-char-count.php
Add a Character Counter to Excerpt box in Edit Post screen (with suggested range).
<?php
/**
* Add a Character Counter to Excerpt box in Edit Post screen.
*
* Includes suggested range.
* Char-count number is color red when outside range and green within.
*
* @link http://wpsites.org/add-character-counter-excerpt-box-10503/
*/
function my_excerpt_count_js() {
@wecodelaravel
wecodelaravel / wp-media-lib-size-col.php
Created May 7, 2019 01:31 — forked from hearvox/wp-media-lib-size-col.php
Add image data to new column to Media Library: file-size (bytes), image dimensions (pixels), and optional ratio between the two.
<?php
/* Add image data column to Media Library */
/**
* Add columns (file-size) to the Media Library list table.
*
* @param array $posts_columns Existing array of columns displayed in the Media list table.
* @return array Amended array of columns to be displayed in the Media list table.
*/
function my_media_columns( $posts_columns ) {
$posts_columns['size'] = __( 'Size', 'headecon' );
@wecodelaravel
wecodelaravel / php-checks.php
Created May 7, 2019 01:31 — forked from hearvox/php-checks.php
Checking php extensions, functions, version, etc.
<?php
echo $check_fn = ( function_exists( 'http_parse_message' ) ) ? 'yo' : 'no';
echo ' ';
echo $check_ext = ( extension_loaded( 'pecl_http' ) ) ? 'yo' : 'no';
if ( class_exists('My_Class') ) {
$my_class = new My_Class();
}
echo 'Current PHP version: ' . phpversion();
@wecodelaravel
wecodelaravel / wp-top-parent-body-class.php
Created May 7, 2019 01:35 — forked from hearvox/wp-top-parent-body-class.php
Add class name for top-level parent category or page to body tag in WordPress posts, pages, and archives.
<?php
/* Add body-class for top-level parent Page or Category */
function topcatpg_body_class( $class ) {
$prefix = 'topic-'; // Editable class name prefix.
$top_cat_pg = 'home'; // Default.
global $top_cat_pg;
// Get class name from top-level Category or Page.
global $wp_query;
if ( is_single() ) {
@wecodelaravel
wecodelaravel / wp-script-vers-filemod.php
Created May 7, 2019 01:35 — forked from hearvox/wp-script-vers-filemod.php
Use filemod timestamp for version number for WordPress script registration, to bust cache.
<?php
/**
* Use filemod timestamp for version number.
*
* For setting cache-busting version number in script registrations. Usage:
* wp_register_script( 'handle', $file_url, array(), headecon_filemod_vers( $file_path ) );
*
* @param string $path Path of script/style file
* @return string $vers File-modification timestamp or WordPress version
*/
@wecodelaravel
wecodelaravel / wp-list-attachments.php
Created May 7, 2019 01:35 — forked from hearvox/wp-list-attachments.php
List all images in all sizes in WordPress Media Library.
<?php
$query_images_args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$query_images = new WP_Query( $query_images_args );
$image_sizes = get_intermediate_image_sizes();
$image_sizes[] = 'full';
@wecodelaravel
wecodelaravel / wp-debug.php
Created May 7, 2019 01:35 — forked from hearvox/wp-debug.php
WordPress PHP debug global variable settings
<?php
/* WordPress debug globals (goes in wp-config.php).
* For Dev sites only!
* @ link https://premium.wpmudev.org/blog/debugging-wordpress-how-to-use-wp_debug/
*/
// Turn debugging on.
define( 'WP_DEBUG', true );
// Log PHP error messages to file: /wp-content/debug.log
define( 'WP_DEBUG_LOG', true );
@wecodelaravel
wecodelaravel / WP-social-meta.php
Created May 7, 2019 01:35 — forked from hearvox/WP-social-meta.php
Change a WordPress site's homepage default social meta added by the Jetpack plugin for Facebook's Open Graph and Twitter Card tags.
<?php
function hearvox_social_meta( $tags ) {
if ( is_home() || is_front_page() ) {
// Remove the default blank tags added by Jetpack
unset( $tags['og:description'] );
unset( $tags['og:image'] );
unset( $tags['twitter:site'] );
unset( $tags['og:title'] );
unset( $tags['og:url'] );
@wecodelaravel
wecodelaravel / logging-helper.php
Created May 7, 2019 01:39 — forked from jdevalk/logging-helper.php
This little hack enables fatal error logging for your site, without creating an error log that is insanely big.
<?php
/**
* This changes logging to only log fatal errors. This file should go in your mu-plugins directory.
*/
// Set the error logging to only log fatal errors
error_reporting( E_ERROR );
// Optional: change the location of your error log, it might be wise to put it outside your WP content dir.
// If you don't change it, the default place for this log is debug.log in your WP_CONTENT_DIR.
@wecodelaravel
wecodelaravel / two-products-best.json
Created May 7, 2019 01:39 — forked from jdevalk/two-products-best.json
Two JSON blobs, one with the main product, a second one that can be output later on the page that clearly relates itself to the first one as a related product.
<script type="application/ld+json">{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": "https://example.com/#organization",
"name": "Yoast",
"url": "https://example.com/",
"sameAs": [
"https://www.facebook.com/yoast",