Category: wordpress

WordPress Error – bypass `reCaptcha v3 test failed`

WordPress Error - bypass reCaptcha v3 test failed

When encounter error when login to WordPress, can temporarily bypass reCaptcha verification

reCaptcha v3 test failed

Solution

Rename folder wp-content/plugins/google-captcha to wp-content/plugins/google-captcha.old, then try to login again.

To enable back, rename back the folder.

References

Fix ‘Briefly Unavailable for Scheduled Maintenance. Check Back in a Minute’ error

Fix ‘Briefly Unavailable for Scheduled Maintenance. Check Back in a Minute’ error

It happened after clicked refresh browser button when updating plugin.

Fix

Remove .maintenance file

References

How to Fix ‘Briefly Unavailable for Scheduled Maintenance. Check Back in a Minute’

Create Multi Related Posts in WordPress

Create Multi Related Posts in WordPress

Create a Post with Posts List

# <Post Title> - Posts List

<Post contain>

## References

[<SubPost_Title1>](<SubPost_URL1>)
[<SubPost_Title2>](<SubPost_URL2>)
[<SubPost_Title3>](<SubPost_URL3>)
[<SubPost_Title4>](<SubPost_URL4>)

SubPost

Add following script after each subpost summary.

Note: The 8888 is the subpost id, 9999 is the index post (Posts List) id. This will create a button on current page (8888) to display Posts List

# <Post Title>

<Post contain>

<div><button id='related_posts_8888'>Display Learning Posts</button>

<script type="text/javascript">
(function($) {
    $(document).ready(function() {
        $("#related_posts_8888").click(function(event) {
            el = $(document.getElementById( $(this).attr('id') ).parentElement);
            $.get("?p=9999", function(data, status) {
                el.html(/h2>References<\/h2>([\s\S]*?)<\/div>/.exec(data)[1]);
            });
        });
    });
}) (jQuery);
</script>
</div>

WordPress ERROR: Please solve Captcha correctly!

WordPress ERROR: Please solve Captcha correctly!

Recently, I got such error quite often when using google reCaptcha v3. To allow me login without reCaptcha verification, login to WordPress server, and rename plugin folder advanced-nocaptcha-recaptcha, then login normally. After login, rename back the folder.

References

Advanced noCaptcha & invisible Captcha (v2 & v3)

Usable Image with Different Size in WordPress

Usable Image with Different Size in WordPress

I was trying to find out the available pictures for same image in WordPress to enable fast download of small pictures in same page.

There are many pictures in different size, they can be found in WordPress html folder. Depending on the media configuration, maybe in different location. Here, only lists default location.

Location

The resized images files are in html/wp-content/uploads/<year>/<month> directory as the format of <picture_name>-<width>x<height>.jpg.

URL

Original image

Can be found at bottom Edit Media page as <picture_name>.jpg.

Scaled image

Can be found in text box File URL as <picture_name>-scaled.jpg

Other size images

Can change the scaled image URL to <picture_name>-<width>x<height>.jpg

Increase upload file size limit for WordPress and NGNIX

Increase upload file size limit for WordPress and NGNIX

There are various ways to do, but the workable way is, updating .htaccess in WordPress and NGNIX configuration file.

Issue

First, tried the way by changing function.php in theme, but no luck. Then updated .htaccess file, it worked.

Then the client gets the error “Request Entity Too Large” (413). This error reported by NGINX.

WordPress

Add following lines in .htaccess file in html directory

php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300

Then the upload page in WordPress should be shown as below

Maximum upload file size: 64 MB.

Alternative

These options are PHP options, which can be applied to php.ini as well as below

upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300

NGINX

Add the following line to http, server or location context in nginx.conf or conf.d/default.conf

client_max_body_size 64M;

Then reload NGINX configure.

# /usr/local/nginx/sbin/nginx -s reload

This will fix the client error “Request Entity Too Large” (413).

Sort posts by last updated date in WordPress

Sort posts by last updated date in WordPress

Solution

In recent post list, the date of sorting is based on published date, so the updates will never be shown. To change this behavior, following code can be appended into functions.php to archive the sorting by last updated date.

function lmt_orderby_modified_posts( $query ) {
    if( $query->is_main_query() && !is_admin() ) {
        if ( $query->is_home() || $query->is_category() || $query->is_tag() ) {
            $query->set( 'orderby', 'modified' );
            $query->set( 'order', 'desc' );
        }
    }
}
add_action( 'pre_get_posts', 'lmt_orderby_modified_posts' );

Issue

There is an issue after changed sorting and modified post day, the archives will still be under published date, which can be comfusing.

If there is a way change permalink structure based on last updated date, then could be much simple.

References

Sort posts by modified date in the frontend
Using Permalinks
Simple Guide to Changing Your Permalinks Without Breaking Your WordPress Site

Last updated date in WordPress

Last updated date in WordPress

There are a few methods to display last updated in WordPress

Change post date to last updated date

But default, post date is published date, if like to change it to last updated date, add additional CSS as below.

/* for post modified */
.entry-date.published { display: none; }
.updated:not(.published) { display: inline-block; }

/* for post that never been modified, theme uses .updated */
.entry-date.published.updated { display: inline-block; }

Change functions.php

function my_last_updated_date( $content ) {
    $u_time = get_the_time('U');
    $u_modified_time = get_the_modified_time('U');

    if ($u_modified_time >= $u_time + 86400) {
        $updated_date = get_the_modified_time('F jS, Y');
        $updated_time = get_the_modified_time('h:i a');
        $custom_content .= '<p class="last-updated entry-meta">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';
    }

    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'my_last_updated_date' );

Change template-tags.php

This is the PHP way to modify the code to display dates.

References

How to replace published date?