Fixing WordPress Excerpts Word Count in Chinese

Fixing WordPress Excerpts Word Count in Chinese

Some users reported that the WordPress excerpts word count is incorrect in Chinese. This PHP snippet should help:

function dez_filter_chinese_excerpt( $output ) {
global $post;
//check if its chinese character input
$chinese_output = preg_match_all("/p{Han}+/u", $post->post_content, $matches);
if($chinese_output) {
$output = sprintf( '%1$s

%3$s

',
mb_substr( $output, 0, 50 ) . '...',
get_permalink(),
__( 'Read more', 'generatepress' )
);
}
return $output;
}
add_filter( 'get_the_excerpt', 'dez_filter_chinese_excerpt' );

Implementing Google Tag Manager

Implementing Google Tag Manager

Using Hooks Element

If you have GP Premium, using our Hooks Element module would be the easiest way to add the code.

The first block of code should look similar to this:


(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');

Go to Appearance > Elements and click 「Add New」. From the Element dropdown list, choose 「Hook」.Copy and paste the your own code into the content area.Under Settings tab, select wp_head in the Hook dropdown list.Under Display Rules tab, select Entire Site in the Location dropdown list.Click the Publish button then we are half way done.

The second block of code should look similar to this:

Go to Appearance > Elements and click 「Add New」. From the Element dropdown list, choose 「Hook」.Copy and paste the your own code into the content area.Under Settings tab, select wp_body_open in the Hook dropdown list and set the Priority to 0.Under Display Rules tab, select Entire Site in the Location dropdown list.Click the Publish button then we are all done.

Using Functions

If you don』t have GP Premium or prefer to use functions, your code should look similar to below:

add_action( 'wp_head', function() {
?>

(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');


<?php
}, 0 );

The functions above need to be added as PHP.

Error Codes While Importing

Error Codes While Importing

Server Error 500

If you get a 500 error (500 Internal Server Error) while importing a Site, it means there』s likely a server error preventing the site from importing.

The following server settings can be increased to better allow GP to upload and process the import files.

upload_max_filesize (256M)max_input_time (300)memory_limit (256M)max_execution_time (300)post_max_size (512M)

These values aren』t perfect, as it depends on the size of the site you』re importing. We like to keep things small, so the above values should be more than enough. If you』re not comfortable tweaking these yourself, your hosting support should be able to help you.

502 bad gateway

This error can happen if you』re on an nginx server. To fix it, you need to add this to your server config file:

fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;

400 Error

400 errors are typically permission-related.

We』ve seen 400 errors happening during import with users using EasyEngine on their servers. More info on that here.

Further Debugging

If the above solutions don』t work, we need to debug further.

Add the following into your wp-config.php file in your root WordPress folder:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );

Run the importer again until your encounter the error.

Now you』ll find a file named debug.log in the wp-content folder on your server. Open this file, and look at the end for any errors.

Display Category Description on First Page only

Display Category Description on First Page only

The category description is displayed on every page of the category archive by default.

If you』d like to display them on the first page of the archive only, try this PHP snippet below:

add_action( 'wp', function() {
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ( 1 !== $page ) {
remove_action( 'generate_archive_title', 'generate_archive_title' );
add_action( 'generate_archive_title', 'tu_custom_paged_archive_title' );
};
}, 20 );

function tu_custom_paged_archive_title() {
?>

<?php
}

generate_inside_post_meta_item_output

generate_inside_post_meta_item_output

The generate_inside_post_meta_item_output filter allows you to add content after the post meta.

For example, we can use this snippet to add the text 「Publish in」 before publishing the category meta:

add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) {
if ( 'categories' === $item ) {
return ' Published in ';
}
return $output;
}, 50, 2 );

Resolving Topics

Resolving Topics

In our support forum, we currently only allow one unresolved topic per user at a time to keep the queue moving for everyone.

If you have an unresolved topic, you won』t be able to start a new topic. Instead, you』ll see a message like this:

Click the 「here」 link to the unresolved topic to open it. If it』s resolved, click the option shown below and set it to 「Resolved」.

Now you』ll be able to open a new topic.

If it』s not resolved yet, please work with us to get it resolved before opening a new topic.

If you urgently need help and have an unresolved topic, feel free to contact us directly through our contact page.

Inline Post Navigation

Inline Post Navigation

By default, the post navigation is stacked like this:

The CSS below would position inline like this:

Icon Type: Font

.post-navigation {
display: flex;
}

.post-navigation .nav-next {
width: 50%;
text-align: right;
}

.post-navigation .nav-previous {
width: 50%;
}

.post-navigation .nav-next .next:before {
display: none;
}

.post-navigation .nav-next .next:after {
font-family: GeneratePress;
text-decoration: inherit;
position: relative;
margin-left: .6em;
width: 13px;
text-align: center;
display: inline-block;
content: "f105";
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-style: normal;
font-variant: normal;
text-rendering: auto;
line-height: 1;
speak: none;
}

Icon Type: SVG

.post-navigation {
display: flex;
}

.post-navigation .nav-next {
width: 50%;
text-align: right;
display: flex;
flex-direction: row-reverse;
}

.post-navigation .nav-previous {
width: 50%;
}

.nav-next .gp-icon {
margin-left: .6em;
margin-right: 0;
}

Move the Comment Form Above Comments

Move the Comment Form Above Comments

The following comments.php file is used to move the comment form from below comments to above comments.

First, install a child theme if you are not using one currently.

Then download the comments.php file here and paste it into your child theme』s folder.

1 && get_option( 'page_comments' ) ) : ?>

    'generate_comment',

    ) );

    ?>

1 && get_option( 'page_comments' ) ) : ?>

view raw

comments.php

hosted with ❤ by GitHub

generate_logo_href

generate_logo_href

The generate_logo_href filter allows you to change the URL destination of your logo.

Default (string): Your URL set in Settings > General

Example

add_filter( 'generate_logo_href', function() {
return "https://NEW-URL-HERE";
} );

Usage

Please refer to the Using Filters article to learn how to use this filter.