Categories
WordPress

How to fix invalid JSON response error in WordPress

Updating failed. The response is not a valid JSON response.

This error appears when edit and update your posts or pages on your WordPress website. You will see message saying “The response is not a valid JSON response” and updating that page would fail. In this article, I will show you how to fix the invalid JSON error in WordPress.

WordPress needs to communicate with the server while you are editing a post or page form WordPress admin and it getting responses from the web hosting server in the background. This response is in JSON format which is used to quickly transport data using JavaScript.

I getting this error when I move my wordpress website to another server.

Solution:

First please confirm your home and siteurl is ok on database wp_options table.

Please go to Settings => Permalinks page. From here, you need to review the WordPress permalink options. Please select “Post name” option form Permalink Settings and click on the Save Changes button to store your settings.

Permalink Settings

Also please confirm those code are available on the .htaccess file.

Now site is ready to edit post or page from WordPress admin.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Hope it will help you.

Categories
WordPress

WordPress – create different template for different post type

In this post we will learn how to create different post template for different post type on TwentyTwentyOne theme. Now we want to create a child theme TwentyTwentyOne-Child as like my previous post How to Create a Child Theme?

Another important thinks, we want to know how to create WordPress custom post type, Please visit my previous post. How to Create WordPress Custom Post Types?

I have created custom post type faqs and create new a post to tested different post template for different post type is working or not.

custom-post-type-posts

Now please go to your child theme directory and crete new single file with custom post type. Example: single-{POST-TYPE}.php wp-content\themes\twentytwentyone-child\single-faqs.php file because my custom post type is “faqs”.

Now copy all code form original single.php file. wp-content\themes\twentytwentyone\single.php Open single.php via editor and copy all code and past on wp-content\themes\twentytwentyone-child\single-faqs.php

Now copy all code form original content-single.php file wp-content\themes\twentytwentyone\template-parts\content\content-single.php Open content-single.php via editor and copy all code and past on wp-content\themes\twentytwentyone-child\template-parts\content\content-faqs.php

Now call new template parts content like this, just change “content-single” to “content-faqs” on single-faqs.php file get_template_part(‘template-parts/content/content-faqs’);

I added some text on new template for texting FAQs custom template

New custom post type template is working.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
WordPress

How to Create WordPress Custom Post Types?

In this post today I will disuse How to Create WordPress Custom Post Types and displaying with Shortcode and page template. Each new developer need to learn how to easily create custom post types in WordPress site. Also WordPress regular blog posts use Categories and Tags to create an organization structure. In this article I also disuse how to crate separate Categories and Tags for custom post types.

Working With Custom Post Types

So your new custom post types need to effectively create and use, you will need to be familiar with the following:

  • Creating custom Post Types
  • Creating custom Taxonomies
  • Creating custom Tags

Creating Custom Post Types

Let’s start and register custom post type in your theme functions.php file by method register_post_type. It will be located in public_html/wp-content/themes/YOUR_THEME_NAME/functions.php Open this file via editor and add following code to register custom post type.

For more information I will shortly describe some args details in below.

  • labels The labels option should be an array defining the different labels that a custom post type can have. I have separated this out above just to make the arguments for registering a post type clearer.
  • description A short explanation of our custom post type, what it does and why we are using it.
  • public This option controls a bunch of things in one go. Setting this to true will set a bunch of other options (all to do with visibility) to true.
  • menu_position Defines the position of the custom post type menu in the back end. Setting it to “7” places it below the “posts” menu.
  • supports This option sets up the default WordPress controls that are available in the edit screen for the custom post type. By default, only the title field and editor are shown.
  • has_archive If set to true, rewrite rules will be created for you, enabling a post type archive at http://yoursite.com/posttype/ (by default)

Our current custom post types Faqs associated with a custom taxonomy called genres. I also set hierarchical to false If you would like your custom post type to behave like Pages, then you can set this value to true.

Category for Custom Post Type

Now we are going to register taxonomy for custom post type named “Faq Categories” after register_post_type method in functions.php file by register_taxonomy method. This categories we only use for Faq post types.

Registering categories for custom post type is done, We added some labels and set hierarchical option to true. This enables custom “category style” to taxonomies. When we set it to false (this is the default), taxonomy will be like the default tags.

Displaying Custom Post Types by Shortcode

Now I am going to create a shortcode [faqs] to displaying custom post type post items. Please added following code in your theme functions.php in theme public_html/wp-content/themes/YOUR_THEME_NAME/functions.php.

We can pass tow parameter via shortcode “category” Example: [faqs category=”7″] (7) is category ID, Second one is “class” Example: [faqs class=”sidebar-categories”] is CSS class.

Displaying Custom Post Types in Template

Also we can listed custom post via template file, open a template file via editor from your theme public_html/wp-content/themes/YOUR_THEME_NAME/ directory. By querying the database, you can retrieve post items from a custom post type.

So in this post we are completed 3 (three) part, 1. Create Custom Post Types, 2. Categories for Custom Post Types, 3. Displaying Custom Post Items by Shortcode and Template.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
WordPress

How to Add New Custom Widget Area?

In this post today I will discus How to Add New Custom Widget Area in WordPress theme. Each new developer need to learn WordPress basics, Also need to know how customize your WordPress site.

After creating new themes developer to customize WordPress themes, So need to know how to create custom Widget area and display Widget area in WordPress theme.

Registering a Custom Widget Area:

Let’s start and registering a widget area add following code in your theme functions.php file by method register_sidebar. It will be located in public_html/wp-content/themes/YOUR_THEME_NAME/functions.php Open this file via editor and add following code to registering new Widget area.

After register a new widget area, WordPress automatically display it as an option under Appearance => Widgets in WordPress admin section. My custom Widget name is “Single Page Top Sidebar” and ID is “sidebar_single_top”.

Registering a Custom Widget Area

Display Your Specific Custom Widget Area:

WordPress not automatically display your newly created Widget area on frontend theme. Because we have not yet told to WordPress where to display newly created Widget area. I have create new widget are for post single page sidebar top place widget area.

Now I need to edit the public_html/wp-content/themes/YOUR_THEME_NAME/singular.php file via editor in your theme and add following code in DIV with .sidebar class to display your custom widget area.

Registering a Custom Widget Area

You can create Widget area for any page section like Header, Sidebar, Page Content and Footer with using PHP WordPress conditions.

Example:
is_front_page()
is_single()
is_page()
is_category()
is_singular()

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.

Categories
WordPress

WordPress – How to Create a Child Theme?

In this post today I will discus, How to Create a Child Theme? Every new developer first need to learn the WordPress basics. Also need to know how customize your WordPress site. Create new child themes is great starting point for developer to customize WordPress themes.

Why Developer Need to Create a Child Theme?

Child themes are considered the best way to customize or extend function your WordPress default or paid themes. A child theme inherits all the features and appearance of its parent theme. Developer can customize without affecting parent theme function.

This allows a developer to easily update parent theme function without losing parent theme new changes. Developer can easily update update parent theme if release new version for parent theme.

Developer Basic Requirements

A developer need to understanding of CSS/HTML/PHP basic, so a developer can make easily own changes. If developer is good at copying and pasting code snippets from other sources, then that would work too. I am recommend a developer to practice on local development environment. Developer can move all local change to live WordPress site. Because on local server developer can dummy content for testing purposes to child theme development.

Creating Your First Child Theme

Now you can chose one of the default WordPress theme can be used as a parent theme. Example: twentytwenty Developer need to open /wp-content/themes/ in your WordPress installation directory and create a new directory (twentytwenty-child) for your child theme. You can name this directory anything you want but good format is like (twentytwenty-child) name.

wordpress-create-child-theme-directory

Go to /wp-content/themes/twentytwenty-child/ directory and create stylesheet file named (style.css) and open with text editor like Notepad or VSCode and your stylesheet must contain the below required header comment at the very top of the file.

Following information is required for child theme:
Theme Name: Needs to be unique to your theme name.
Template: The name of the parent theme directory. The parent theme in our example is the Twenty Twenty theme, so the Template will be twentytwenty. The parent theme folder name is case-sensitive. If you provide with Template – TwentyTwenty, then it will not work.

Now developer need to something change on functions.php file, it’s necessary to add parent theme styles by (parent-style) on child theme and custom stylesheet called by (child-style).

Now developer need to something change on functions.php file, If you want to set logo without cropping logo. Login into wp-admin and go to Appearance => Customize after than click on “Site Identity” try to change logo, select a logo and press Skip Cropping button with following code.

wordpress-create-child-theme-cropping

Activate child theme:

Child theme is ready for active. Please go to WordPress admin and go to menu Appearance => Themes you can find new theme “Twenty Twenty Child” mouse over on new theme and click on “Active” button.

wordpress-create-child-theme-active

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this post.