Giter Site home page Giter Site logo

freshy969 / wp-polylang-translate-rewrite-slugs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from klicher/wp-polylang-translate-rewrite-slugs

0.0 1.0 0.0 368 KB

Wordpress plugin to help translate post types rewrite slugs with the Polylang plugin.

PHP 100.00%

wp-polylang-translate-rewrite-slugs's Introduction

Polylang - Translate URL Rewrite Slugs

WordPress plugin that add rewrite url slugs translation feature to Polylang.

Work in progress ;)

Upgrade notice < 0.3.0

If you used a version prior to 0.3.0, the plugin will probably crash as the structure of the param for the "pll_translated_post_type_rewrite_slugs" filter has changed.

Translate Post Type URLs

Translate rewrite slugs for post types by doing 5 things:

  • Remove original extra rewrite rules and permastruct for these post types;
  • Translate the extra rewrite rules and permastruct for these post types;
  • Stop Polylang from translating rewrite rules for these post types;
  • Fix "get_permalink" for these post types.
  • Fix "get_post_type_archive_link" for these post types.

To translate a post type rewrite slug, add the filter "pll_translated_post_type_rewrite_slugs" to your functions.php file or your plugin and add the "has_archive" and "rewrite" key has you normally do for the params of the "register_post_type" Wordpress function but add it for each post type and language you want.

Example

<?php
add_filter('pll_translated_post_type_rewrite_slugs', function($post_type_translated_slugs) {
	// Add translation for "product" post type.
	$post_type_translated_slugs = array(
		'product' => array(
			'fr' => array(
				'has_archive' => true,
				'rewrite' => array(
					'slug' => 'produit',
				),
			),
			'en' => array(
				'has_archive' => true,
				'rewrite' => array(
					'slug' => 'product',
				),
			),
		),
	);
	return $post_type_translated_slugs;
});
?>

wp-polylang-translate-rewrite-slugs's People

Contributors

idflood avatar klicher avatar tanelkarp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.