Tagged: wordpress

Solve “rediect too many times” in WordPress during migration

Problem: I’m using CentOS + Nginx + MySQL + phpMyAdmin. and all config is correct, which includes all the DB tables (domain updated), wp-config.php. but still encounter too many redirect problem.

Solution: If you sure you set up correctly, you can first delete all your tables, but not your database.

Then open https://yourdomain/wp-admin/install.php. Try to install the tables through WordPress wizard.

After you can enter the newly created default website, then go back to phpMyAdmin. Import the MySQL file again, it is ok to overwrite the original. Finally the problem solved.

Remove emoji function in WordPress

Problem: WordPress forced to add emoji function since version 4.2 and want to remove it.

Solution: In the theme folder that you are using, add below code to functions.php:

remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );

Change WordPress index page content without affect the widget section.

Problem: Want to change WordPress index page content from post to page.

Solution: First go to /var/www/html/[website]/wp-content/themes/twentyseventeen/index.php, follow below content

 * The main template file
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0

get_header(); ?>

<div class="wrap">
	<?php if ( is_home() && ! is_front_page() ) : ?>
		<header class="page-header">
			<h1 class="page-title"><?php single_post_title(); ?></h1>
	<?php else : ?>
	<header class="page-header">
		<h2 class="page-title"><?php _e( 'Posts', 'twentyseventeen' ); ?></h2>
	<?php endif; ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">
			if ( have_posts() ) :

				/* Start the Loop */
			//	while ( have_posts() ) :
			//		the_post();

					 * Include the Post-Format-specific template for the content.
					 * If you want to override this in a child theme, then include a file
					 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
		 //	get_template_part( 'template-parts/post/content', get_post_format() );
	 $id = 1267;
 $post = get_page($id);
 $content = apply_filters('the_content', $post->post_content);
 echo $content;

			/*	the_posts_pagination(
						'prev_text'          => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
						'next_text'          => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
						'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',

			else :

				get_template_part( 'template-parts/post/content', 'none' );


		</main><!-- #main -->
	</div><!-- #primary -->
	<?php get_sidebar(); ?>
</div><!-- .wrap -->


keep in mind that the replace $id = 1267; 1267 is the page id.

Fatal error: Uncaught Error: Call to undefined function set_magic_quotes_runtime() in WordPress

Problem: When trying to import RSS via a built-in plugin, there is an error occurred Call to undefined function set_magic_quotes_runtime()

If you are using PHP 5.3 or after, set_magic_quotes_runtime() is already deprecated, although it will not cause a Fatal error it will send an E_DEPRECATED warning.

Solution: Remove all set_magic_quotes_runtime() in the WordPress project

Remove author name from every post in WordPress

Problem: the author’s name always shows as “Root” which is meaningless to the reader.

Solution: First go to /wp-content/themes/twentyseventeen/ folder, since I use twentyseventeen so I go to twentyseventeen folder, please change to your theme folder according to your website theme using.

then search “post author” in template-tags.php file, or find it on functions.php file, you will see similar content below(except the function name is different):

function twentynineteen_posted_by() {
            /* translators: 1: SVG icon. 2: post author, only visible to screen readers. 3: author link. */
            '<span class="byline">%1$s<span class="screen-reader-text">%2$s</span><span class="author vcard"><a class="url fn n" href="%3$s">%4$s</a></span></span>',
            twentynineteen_get_icon_svg( 'person', 16 ),
            __( 'Posted by', 'twentynineteen' ),
            esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
            esc_html( get_the_author() )

remove all the content and save:

function twentynineteen_posted_by() {

Error “cURL error 18: transfer closed with 7622473 bytes remaining to read” occurred when upgrading WordPress.

Problem: When trying to upgrade WordPress to version 5.3.1. There are a message showing that the installation failed.

After googling the error message. I find out that it caused by a Google plugin.

Solution: In my case, it caused by the Chrome plugin problem; If you install some plugin that will block recourse or URL like AdBlock, Privacy Badger. please turn it off first, or use another browser to upgrade WordPress.

Require FTP login when installing WordPress plugins

Problem: when trying to install a plugin via whether manually upload or WordPress plugin page. There is a pop-up box that requires you to fill FTP username and password.

If people do not know their FTP login username and password, they never able to install wp plugin 🙁

Solution: In wp-config.php , add below line at the end of the file

define('FS_METHOD', 'direct' );

to force WordPress to write files directly. And you may also need to change the permission in wp-content and wp-includes

For the risk of adding FS_METHOD DIRECT please check out this post.

WordPress image in poor quality/ image being resized

Problem: Upload some images with high quality, somehow showing a poor quality or showing a resized image URL at the end.

There are a few possible things causing this like third party plugin and auto-cropping images function.

Solution: First if you installed some optimize tools like Jetpack please disable it or turn off Image Accelerator.

According to this post, add below code into functions.php located in the themes folder that you are using.

add_filter( 'post_thumbnail_html', 'remove_wps_width_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_wps_width_attribute', 10 );
function remove_wps_width_attribute( $html ) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;

or according to this, add below code to remove size attribute

add_filter( 'wp_calculate_image_srcset_meta', '__return_null' );