All posts by Keyboard

Change WordPress heartbeat rate to lower server load

WordPress heartbeat is made to save your articles automatically but it can slow down your server depending on your site size and all the plugins you got. If you’d like to stil use the feature but lower its saving rate, you can use the following code :

add_action( 'init', 'customize_heartbeat', 1 );

function customize_heartbeat() {

// Register the wordpress native script if necessary

if (!wp_script_is('heartbeat', 'registered')) {

wp_register_script('heartbeat', includes_url('js/heartbeat.min.js'), array('jquery'), null, true);

}

// Active with a custom interval

add_filter('heartbeat_settings', 'set_heartbeat_interval');

}

function set_heartbeat_interval($settings) {
 // Define interval in seconds
 $settings['interval'] = 120; // Example for 2 minutes (60x2)
 return $settings;
 }

How to add a custom H1 title to a tag page

By default wordpress writes an H1 with the tag term, which can be very limited in terms of SEO. For instance, you may have a tag page title “USA” instead of “News from the United States of America” if your tag is only “USA”. To improve that without any plugin, open your theme’s functions.php file and add the following lines :


/*
CUSTOM H1 TITLES FOR TAGS PAGES by Ghyslain 3 mai 2023
*/

function add_custom_h1_title_field( $term ) {
$term_id = $term->term_id;
$custom_h1_title = '';
if ( isset( $_POST['custom_h1_title'] ) ) {
$custom_h1_title = sanitize_text_field( $_POST['custom_h1_title'] );
} elseif ( $term_id ) {
$custom_h1_title = get_term_meta( $term_id, 'custom_h1_title', true );
}
?>
<div class="form-field term-group">
<label for="custom_h1_title"><?php _e( 'Custom H1 title', 'text-domain' ); ?></label>
<input type="text" class="form-field" name="custom_h1_title" id="custom_h1_title" value="<?php echo esc_attr( $custom_h1_title ); ?>">
</div>
<?php
}

add_action( 'post_tag_edit_form_fields', 'add_custom_h1_title_field' );
add_action( 'product_tag_add_form_fields', 'add_custom_h1_title_field' );

function save_custom_h1_title_field( $term_id ) {
if ( isset( $_POST['custom_h1_title'] ) ) {
update_term_meta( $term_id, 'custom_h1_title', sanitize_text_field( $_POST['custom_h1_title'] ) );
}
}
add_action( 'edited_post_tag', 'save_custom_h1_title_field' );
add_action( 'created_post_tag', 'save_custom_h1_title_field' );

You will get a new text field in your admin edit screen called “Custom H1 title”.
Now in your theme’s tag.php file, replace the lines where the H1 was being called by :

$custom_h1_title = get_term_meta(get_queried_object_id(), 'custom_h1_title', true);
if ($custom_h1_title) {
echo esc_html($custom_h1_title);
} else {
single_tag_title();
}

WordPress : How to disable updates for a specific plugin

If you modified a plugin and don’t want it to appear in the updates list, use this function from rniswonger in your functions.php

/**
 * Prevent update notification for plugin
 * http://www.thecreativedev.com/disable-updates-for-specific-plugin-in-wordpress/
 * Place in theme functions.php or at bottom of wp-config.php
 */
 function disable_plugin_updates( $value ) {
    $pluginsToDisable = [
        'plugin-folder/plugin.php',
        'plugin-folder2/plugin2.php'
    ];
    if ( isset($value) && is_object($value) ) {
        foreach ($pluginsToDisable as $plugin) {
            if ( isset( $value->response[$plugin] ) ) {
                unset( $value->response[$plugin] );
            }
        }
    }
    return $value;
}
add_filter( 'site_transient_update_plugins', 'disable_plugin_updates' );

How CM Tooltip glossary can slow down WordPress

If you’re using CM ToolTip glossary pro and noticed an abnormal decrease in page speed on your WordPress installation, that might be caused by an option set in CM ToolTip configuration. It came out my SQL database was full of transients, these entries created by some (usually bad coded) plugins to store data in order to increase SQL requests speed. It turned out the cache system used on CM Tooltip glossary did exactly the contrary in my case.

After few hours looking for a solution to my problem I’ve finally disabled the cache option as shown below :

Set the cache on off to avoid excessive transients creation in your SQL database

The site where it happened has few thousands of articles already published, so I’m guessing CM ToolTip glossary was parsing all of them when a user requested the page in order to find items that match the glossary index. SQL overload went so far that several hundreds of thousands transients were created and literally crashed my server after a while.

Clean transients manually and automatically

A plugin that really helped me to analyse how WordPress was reacting to these CM Tooltip glossary settings is Transient Cleaner. I strongly advise any wordpress user to use that plugin as a routine to periodically clean his database. Your site speed will feel the difference.

I also removed search engine plugin Ajax Search Pro,  it doesn’t work that well for me and made really bad sql requests.

Paypal bank account confirmation issue : two digits only

Confirming your bank account with Paypal can be a little bit disappointing sometimes. My last bad experience was about the amounts sent on my account that are supposed to be used through the confirmation process.

If Paypal sent you 0.06$ you have to enter 06 only. The text field used in their confirmation form is a two digits only and they don’t explain that. So don’t waste your time trying to enter 0.06, just use the last two digits (06 in this case) and you’re good to go.

Magpie RSS and special characters

Your site is not in english and you are trying to import an RSS feed by using the excellent Magpie RSS ? If the feed language is in french for instance you’ll probably get weird characters coming up on your display page.

The solution is pretty simple. Go in the folder where Magpie RSS is installed and look for rss_fetch.inc

Around line 357 set the default output and input encoding to UTF-8 like this :

  if ( !defined('MAGPIE_OUTPUT_ENCODING') ) {
 define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
 }
 
 if ( !defined('MAGPIE_INPUT_ENCODING') ) {
 define('MAGPIE_INPUT_ENCODING', 'UTF-8');
 }

Disqus now forces Ads in its free version

That has to come one day. The famous commenting system that many WordPress administrators love has just announced that advertising will now come by default in its free version. If you want to remove theses ads, you’ll just have to pay 10$/month. A very fair way to thank its users who contribute to make the system famous.

Here’s the announcement :


Hi there,

We recently announced our plans for the new year including releasing new versions of Disqus with professional features. Disqus will always offer a free-to-use version that is supported by advertising. We are reaching out to you because you previously opted out of running advertising from Disqus.

Starting February 8, publishers running the free-to-use version of Disqus will be supported by advertising. Advertising will continue to be configurable for your site. We know that advertising is not the right fit for all publishers and that is why we are excited to offer publishers the option to pay a monthly subscription of $10 to remove advertising altogether.

We’d like to hear from you. If you are interested in the upgraded version of Disqus, please click below and we will reach out to you.