Skip to content
Advertisement

WordPress same custom post template for different languages

I have a WordPress webpage where a former web developer created a custom post type using Pods pulgin, on this custom post type there is a post that we can call “Ejemplo”, that post uses content-single-ejemplo.php to be build but the english version “Example” is being created with content-single.php.

What should I do to use the same content-single-example.php for the same post on both languages instead of content-single.php for the english version? (We are using the plugin WPML for translations)

I’ve already tried cloning the content-single-ejemplo.php and rename it as content-single-example.php but it still doesn’t work.

Advertisement

Answer

content-single.php or content-single-post_type.php are NOT part of the regular WordPress template hierarchy nor a post template file. In your case it’s probably a custom template part. Meaning that it as no default fallback nor redundancies and as no ties to the WordPress core functionalities.

A template part is loaded on the front-end via the handy function get_template_part.

Loads a template part into a template. Provides a simple mechanism for child themes to overload reusable sections of code in the theme. Includes the named template part for a theme or if a name is specified then a specialised part will be included. If the theme contains no {slug}.php file then no template will be included.
The template is included using require, not require_once, so you may include the same template part multiple times.
For the $name parameter, if the file is called “{slug}-special.php” then specify “special”.

– Source @ https://developer.wordpress.org/reference/functions/get_template_part/

In short, the content from a template part is just a reusable piece of code.

Currently both of them (content-single.php and content-single-ejemplo.php) are ALREADY using the same end-file, which is probably single.php and I’m guessing that content-single.php and content-single-ejemplo.php are just loops, one for each language.

If you want somebody to be able to help you, you should include the content from both file, content-single.php and content-single-ejemplo.php and the parent file, which is probably single.php.


Learn more

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement