Skip to content

Instantly share code, notes, and snippets.

View barrykooij's full-sized avatar
:shipit:
I may be slow to respond.

Barry Kooij barrykooij

:shipit:
I may be slow to respond.
View GitHub Profile
<?php
function rp4wp_example_remove_hook() {
$hook_instance = RP4WP_Manager_Hook::get_hook_object( 'RP4WP_Hook_Frontend_Css' );
remove_action( 'wp_head', array( $hook_instance, 'run' ), $hook_instance->get_priority() );
}
add_action( 'init', 'rp4wp_example_remove_hook' );
<?php
// Display related posts of current post
rp4wp_children();
// Display related posts of specific post
rp4wp_children( 2 );
// Return output instead of displaying it
@barrykooij
barrykooij / rp4wp-change-excerpt-length.php
Created November 16, 2014 19:26
Related Posts for WordPress Change Excerpt Length
<?php
function rp4wp_change_post_excerpt_length( $excerpt_length ) {
return '10';
}
add_filter( 'rp4wp_general_post_excerpt_length', 'rp4wp_change_post_excerpt_length' );
Correct:
<?php echo $name; ?>
Incorrect:
<?= $name ?>
<?php
$shout = ( 'WordPress' === $cms ) ? 'Woo!' : 'Boo!';
<?php
if ( true == $result ) {
// Do something
}
<?php
/**
* This works
*/
add_option( 'verykey', 'wow' ); // Stored with key 'verykey'
echo get_option( 'verykey', '' ); // Outputs 'wow'
/**
<?php
// The changelog path
$changelog_path = '/var/www/rp4wp/wp-content/plugins/related-posts-for-wp-premium/CHANGELOG.md';
// Format the changelog from .md to HTML
$changelog = file_get_contents( $changelog_path );
$changelog = preg_replace( "/###[ ]?([0-9\.]+): ([A-Z0-9 ,]+)/i", "<h3>$1</h3>" . PHP_EOL . "<i>$2</i>" . PHP_EOL . "<ul>", $changelog );
$changelog = preg_replace( "/\* ([A-Z0-9 \._,'\(\)\/\-&\"\']+)/i", "<li>$1</li>", $changelog );
$changelog = preg_replace( "/" . PHP_EOL . "<h3>/i", "</ul>" . PHP_EOL . PHP_EOL . "<h3>", $changelog );
@barrykooij
barrykooij / CHANGELOG.md
Created November 26, 2014 13:50
CHANGELOG.md

1.2.3: November 25, 2014

  • Added related post id as second argument to 'rp4wp_post_excerpt' filter.
  • Only run upgrade script if there are posts to upgrade.
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly