Conditionally disable Jetpack’s Infinite Scroll

So you implemented Jetpack’s Infinite Scroll feature in your theme, but you don’t want it in a particular page, say a category archive page. Here’s the code you need to add to your theme’s functions.php file:

 * Disable Jetpack's Infinite Scroll Conditionally
function _kucrut_disable_jetpack_infinite_scroll_conditionally() {
	if ( true === my_conditionals() ) {
		remove_theme_support( 'infinite-scroll' );
add_action( 'template_redirect', '_kucrut_disable_jetpack_infinite_scroll_conditionally', 9 );

Just remember to change my_conditionals() with your actual conditionals and to never add the action callback after priority 9, otherwise it will be too late ūüėČ

Forward requests to another host with iptables

Like the cool kids in the block, I too am using Vagrant in my web development workflow. Everything is fine until I need to test the sites with real mobile browsers. Since the sites I’m working on are hosted inside a virtual machine, it’s not accessible from outside of the host machine.

Here’s how we can solve this using iptables. Let’s assume that the host machine’s IP is and the guest/virtual machine’s IP is These commands are to be run in the host machine as root:

iptables -F
iptables -t nat -F
iptables -X
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination
iptables -A FORWARD -d -p tcp --dport 80 -j ACCEPT
iptables -t nat -A POSTROUTING -j MASQUERADE

Now, add the site’s domain to your rooted phone’s /etc/hosts file or your router’s configs:

You can save the rules above permanently with:

iptables-save > /etc/iptables/iptables.rules

Set attachment’s default “Link To” value

attachment-display-settings When inserting an attachment into a WordPress post, we can customize how it should be displayed. There are three settings; Alignment, Link To and Size. Here’s how we can tell WordPress to select None as the default value of Link To:

 * Set default media link to 'none'
 * @param   string $value Option value
 * @wp_hook filter pre_option_image_default_link_type
 * @return  string
function _kucrut_image_default_link_type( $value ) {
    return 'none';
add_filter( 'pre_option_image_default_link_type', '_kucrut_image_default_link_type' );

As of WordPress 4.0, there are four values available: file (default), post, custom and none.

Get ACF Repeater field value

So you’re using ACF‘s repeater field to store your data and are wondering if there’s an easier way to get its value? Here’s how:

 * Get ACF repeater field value
 * @param int|object $post          Post ID/object
 * @param string     $meta_key      Meta key
 * @param array      $subfield_keys Subfield keys
 * return mixed
function kucrut_get_acf_repeater_field_value( $post, $meta_key, Array $subfield_keys ) {
    $post = get_post( $post );
    if ( ! ( $post instanceof WP_Post ) ) {
        return false;

    $count = absint( get_post_meta( $post->ID, $meta_key, true ) );
    if ( empty( $count ) ) {
        return false;

    $values = array();
    for ( $i = 0; $i < $count; $i++ ) {
        $item = array();
        foreach ( $subfield_keys as $sub_key ) {
            $item[ $sub_key ] = get_post_meta(
                sprintf( '%s_%d_%s', $meta_key, $i, $sub_key ),
        $values[] = $item;

    return $values;

Additional Fields for Soliloquy Images

So… I was asked to convert an HTML template into a a WordPress page template, and it has two sliders. A friend of mine recommended me to use Soliloquy, which is a very nice plugin. However, since I didn’t want to mess with the markup and styling, I opted to only use Soliloquy’s backend.
Continue reading Additional Fields for Soliloquy Images

Custom byline markup for Co-Authors Plus

Co-Authors Plus is a nice plugin for assigning multiple authors to posts. However, I find its template tag for displaying byline rather limiting because sometimes we want to use fancy markup for the byline (think of avatars, publish/modification dates, etc). You can use the code below as the base for your theme’s byline markup (in this example, we’re overriding twentyfourteen_posted_on()):
Continue reading Custom byline markup for Co-Authors Plus

WordPress Plugins Localization

A few days ago, I created an Indonesian translation for the Stream plugin. It’s been a while since I used POEdit to create/update translations, so this post will serve as a reminder for me. :)

Before creating the translation for the Stream plugin, I needed to make some changes to the translatable strings so that translators can freely place the tokens. As we all know, each language has its own style, structure, and whatnot, so forcing the order of words in a sentence is a bad idea.
Continue reading WordPress Plugins Localization