Deprecated: Return type of Give\Framework\FieldsAPI\Contracts\Node::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/codexcoach.com/wp-content/plugins/give/src/Framework/FieldsAPI/Contracts/Node.php on line 29

Deprecated: DateTime::__construct(): Passing null to parameter #1 ($datetime) of type string is deprecated in /var/www/codexcoach.com/wp-includes/script-loader.php on line 333

Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/codexcoach.com/wp-includes/Requests/Cookie/Jar.php on line 63

Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/codexcoach.com/wp-includes/Requests/Cookie/Jar.php on line 73

Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/codexcoach.com/wp-includes/Requests/Cookie/Jar.php on line 89

Deprecated: Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/codexcoach.com/wp-includes/Requests/Cookie/Jar.php on line 102

Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/codexcoach.com/wp-includes/Requests/Cookie/Jar.php on line 111

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/codexcoach.com/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 40

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/codexcoach.com/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 51

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/codexcoach.com/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 68

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/codexcoach.com/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 82

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/codexcoach.com/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 91

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/codexcoach.com/wp-includes/class-wp.php on line 173
How to add /blog/ in front of your single post URLs in WordPress - CodeXCoach
Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/codexcoach.com/wp-includes/formatting.php on line 4952

Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/codexcoach.com/wp-includes/formatting.php on line 4952

Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/codexcoach.com/wp-includes/wp-db.php on line 3030

Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/codexcoach.com/wp-includes/wp-db.php on line 3030
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;
}

?>


Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/codexcoach.com/wp-includes/wp-db.php on line 3030

Related Post


Custom Pagination in WordPress

For custom pagination Add Following code in your current themes functions.php file.

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.

Set time Zone by Country

Include the following code file to your current themes functions.php file. Users can see all time by their country timezone wise.

Create Custom Repeater Control Elementor

Easy way to create Repeater control widget for Elementor. Create wc-custom-post-widget.php file and include its to functions.php file(This file is located in your theme folder). You can use below code to include file wc-custom-post-widget.php. include 'wc-custom-post-widget.php'; Elementor has a special type of control called a Repeater, which can contain other controls.Repeaters create sub-items that are […]

How to create custom widgets in wordpress

Include the following code file to your current themes functions.php file Here is the code for sidebar register.

Enable SVG Support in WordPress

For Enable svg support you’ll need to add the following code to your current themes functions.php file.


Leave a Reply

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