Creating a Shortcode

Creating a Shortcode

The PHP snippet below provides an example to use [my_shortcode] to output text string of 「short code example」:

add_shortcode( 'my_shortcode', function() {
ob_start();
// Start your PHP below

echo 'short code example';

// End your PHP above
return ob_get_clean();
} );

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.

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_footer_meta_post_types

generate_footer_meta_post_types

This filter allows you to tell the footer entry meta to display on your custom post types. By default, it only shows for the post post type.

add_filter( 'generate_footer_meta_post_types', function( $types ) {
$types[] = 'my-post-type';
$types[] = 'recipes';

return $types;
} );

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.

Footer Bar Widget Area

Footer Bar Widget Area

You can add widgets into the footer bar, which is the area that holds your copyright message.
This can be super useful for adding things like menus or social icons.
Adding a footer menu
First, you want to create a new menu in Appearance > Menus that will be dedicated to your footer. You can learn how to that here.
Then, go to Appearance > Widgets and drag the Navigation Menu widget into the Footer Bar widget area.
Inside that widget, you can select your newly created menu.
Adding social icons
You can use a plugin like Lightweight Social Icons which adds a social icon widget to your site, or you can use a menu along with Font Awesome as explained in this article.
Footer Bar Alignment
By default, there』s 3 different position for the footer bar – left, center and right.
You can choose your alignment in Customize > Layout > Footer.

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;
}

generate_category_list_output

generate_category_list_output

The generate_category_list_output filter controls the output of your categories as shown in your post meta along with your blog posts.

For example, we can use this PHP snippet to remove the link attached to the category output:

add_filter( 'generate_category_list_output', function() {
$categories = apply_filters( 'generate_show_categories', true );

$term_separator = apply_filters( 'generate_term_separator', _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ), 'categories' );
$categories_list = get_the_category_list( $term_separator );

return sprintf( '%3$s%1$s %2$s ', // WPCS: XSS ok, sanitization ok.
esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ),
strip_tags( $categories_list ),
apply_filters( 'generate_inside_post_meta_item_output', '', 'categories' )
);
} );