Deprecated: Required parameter $field follows optional parameter $i in /var/www/codexcoach.com/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-repeater.php on line 715

Deprecated: Required parameter $post_id follows optional parameter $i in /var/www/codexcoach.com/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-repeater.php on line 715

Deprecated: Required parameter $field follows optional parameter $i in /var/www/codexcoach.com/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-repeater.php on line 781

Deprecated: Required parameter $post_id follows optional parameter $i in /var/www/codexcoach.com/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-repeater.php on line 781

Deprecated: Required parameter $field follows optional parameter $name in /var/www/codexcoach.com/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php on line 1052

Deprecated: Required parameter $field follows optional parameter $i in /var/www/codexcoach.com/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php on line 1088

Deprecated: Required parameter $post_id follows optional parameter $i in /var/www/codexcoach.com/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php on line 1088

Deprecated: Required parameter $field follows optional parameter $i in /var/www/codexcoach.com/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php on line 1140

Deprecated: Required parameter $post_id follows optional parameter $i in /var/www/codexcoach.com/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-flexible-content.php on line 1140

Deprecated: Required parameter $field follows optional parameter $id in /var/www/codexcoach.com/wp-content/plugins/advanced-custom-fields-pro/pro/fields/class-acf-field-gallery.php on line 300
How to add /blog/ in front of your single post URLs in WordPress - CodeXCoach
WordPress
October 9, 2021

How to add /blog/ in front of your single post URLs in WordPress

when we want to add /blog/ only for wordpress default post, add Following code in your current themes functions.php File.

post_type == ‘post’ ) {
return home_url( ‘/blog/’ . $post->post_name );
}
return $post_link;
}

you have to add below code also.

add_action( ‘generate_rewrite_rules’, ‘generate_rewrite_rules’,99,1 );

function generate_rewrite_rules( $wp_rewrite ) {
$new_rules = array(
‘(.?.+?)/page/?([0-9]{1,})/?$’ => ‘index.php?pagename=$matches[1]&paged=$matches[2]’,
‘blog/([^/]+)/?$’ => ‘index.php?post_type=post&name=$matches[1]’,
‘blog/[^/]+/attachment/([^/]+)/?$’ => ‘index.php?post_type=post&attachment=$matches[1]’,
‘blog/[^/]+/attachment/([^/]+)/trackback/?$’ => ‘index.php?post_type=post&attachment=$matches[1]&tb=1’,
‘blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$’ => ‘index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]’,
‘blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$’ => ‘index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]’,
‘blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$’ => ‘index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]’,
‘blog/[^/]+/attachment/([^/]+)/embed/?$’ => ‘index.php?post_type=post&attachment=$matches[1]&embed=true’,
‘blog/[^/]+/embed/([^/]+)/?$’ => ‘index.php?post_type=post&attachment=$matches[1]&embed=true’,
‘blog/([^/]+)/embed/?$’ => ‘index.php?post_type=post&name=$matches[1]&embed=true’,
‘blog/[^/]+/([^/]+)/embed/?$’ => ‘index.php?post_type=post&attachment=$matches[1]&embed=true’,
‘blog/([^/]+)/trackback/?$’ => ‘index.php?post_type=post&name=$matches[1]&tb=1’,
‘blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$’ => ‘index.php?post_type=post&name=$matches[1]&feed=$matches[2]’,
‘blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$’ => ‘index.php?post_type=post&name=$matches[1]&feed=$matches[2]’,
‘blog/page/([0-9]{1,})/?$’ => ‘index.php?post_type=post&paged=$matches[1]’,
‘blog/[^/]+/page/?([0-9]{1,})/?$’ => ‘index.php?post_type=post&name=$matches[1]&paged=$matches[2]’,
‘blog/([^/]+)/page/?([0-9]{1,})/?$’ => ‘index.php?post_type=post&name=$matches[1]&paged=$matches[2]’,
‘blog/([^/]+)/comment-page-([0-9]{1,})/?$’ => ‘index.php?post_type=post&name=$matches[1]&cpage=$matches[2]’,
‘blog/([^/]+)(/[0-9]+)?/?$’ => ‘index.php?post_type=post&name=$matches[1]&page=$matches[2]’,
‘blog/[^/]+/([^/]+)/?$’ => ‘index.php?post_type=post&attachment=$matches[1]’,
‘blog/[^/]+/([^/]+)/trackback/?$’ => ‘index.php?post_type=post&attachment=$matches[1]&tb=1’,
‘blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$’ => ‘index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]’,
‘blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$’ => ‘index.php?post_type=post&attachment=$matches[1]&feed=$matches[2]’,
‘blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$’ => ‘index.php?post_type=post&attachment=$matches[1]&cpage=$matches[2]’,
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}

?>

Related Post


Adding Custom Meta Fields to Taxonomies in WordPress

For add Custom Meta Field in taxonomy use following code in your current themes functions.php file.

How To Create Meta Boxes in WordPress

A meta box is a draggable box displayed in the post editing screen in the backend of WordPress. Users can select or enter extra information in meta boxes addition to the content in the main post editing area. There are two types of data you can enter in meta boxes: metadata (i.e. custom fields), and […]

Increasing the WordPress Memory Limit

This article for increase memory limit in WordPress. Below are some ways to increase memory limit. Edit wp-config.php file First you need to edit the wp-config.php file on your WordPress site. It is located in your WordPress site’s root folder, and you will need to use an FTP client or file manager in your web […]

Disable Payments on WooCommerce

You are using WooCommerce for your eCommerce website. A thing is you want to disable payment on your website, but disabling in WooCommerce payment setting WooCommerce > Settings > Payments will not work and display There are no payment methods available. Add this code to functions.php file of theme.

Delete Old Post in WordPress

We want to delete old post in easy way, Add the following code to your current themes functions.php file and reload your page and see your post may have been deleted.

Display Popular Tags in WordPress

you’ll need to add following code to your current themes functions.php file.


Leave a Reply

Your email address will not be published. Required fields are marked *