How to remove blog page from wpml plugin

51 Views Asked by At

We are use WPML plugin in Wordpress to manage multilingual content, but we need to remove the blog page and its associated posts within WPML.

Also, we need to avoid the automatic generation of default URLs for these elements in every language.

Any idea? Thank you!

If tried to disable the pagination too, but not useful to prevent de default generation of an url

    function disable_blog_pagination($query) {
        if( is_home() && $query->is_main_query() ) {
            $query->set('nopaging', true); 
        }
     }

    add_action('pre_get_posts', 'disable_blog_pagination');
1

There are 1 best solutions below

0
Ali Raza On

Remove the Blog Page:

In your WordPress admin, go to "Pages" and locate the page set as your blog page (usually named "Blog" or "Posts"). Edit this page and change its language to "All Languages" (neutral). Save the changes. This will effectively remove the association of the blog page with a specific language in WPML.

Prevent Default URL Generation:

To prevent the automatic generation of default URLs for this page in all languages, you can use the following code in your theme's functions.php file:

function prevent_default_url_generation($url, $post, $lang, $original_url) {
    if (is_home()) {
        return '';
    }
    return $url;
}

add_filter('wpml_permalink', 'prevent_default_url_generation', 10, 4);

This code hooks into the WPML permalink filter and returns an empty string for the blog page's URL in all languages, effectively preventing default URLs from being generated