Skip to content

Instantly share code, notes, and snippets.

@wecodelaravel
wecodelaravel / SeoMeta.php
Created May 7, 2019 01:41 — forked from izzygld/SeoMeta.php
Add: SEO Meta Fields WP-Graphql shema
add_action( 'wp_loaded', 'wpse290170_wp_loaded' );
function wpse290170_wp_loaded() {
$types = get_post_types( [
'public' => true
] );
foreach ( $types as $type ){
add_action( "graphql_" . $type . "_fields", function($fields) {
$fields['seo_title'] = [
@wecodelaravel
wecodelaravel / gist:e61f9304b546d83dfe2d836375a42b4b
Created May 7, 2019 01:40 — forked from jdevalk/gist:0b2ddd13d27cf869a976
Change WP SEO JSON+LD search URL from ?s= to /search/
<?php
/**
* Changes the search slug to /search/ for the JSON+LD output
*/
function yst_change_json_ld_search_url() {
return trailingslashit( home_url() ) . 'search/{search_term}';
}
add_filter( 'wpseo_json_ld_search_url', 'yst_change_json_ld_search_url' );
@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",
@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 / 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 / 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-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-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-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 / 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();