<?php
/**
* WordPress Türkçe Çeviri Fonksiyonları
* Developer: Berat K - 0539 511 56 32
* Child tema functions.php dosyasına eklenecek kodlar
*/
function custom_rewrite_rules() {
add_rewrite_rule(
'^projeler/?$',
'index.php?post_type=project',
'top'
);
add_rewrite_rule(
'^projeler/([^/]+)/?$',
'index.php?post_type=project&name=$matches[1]',
'top'
);
add_rewrite_rule(
'^blog/?$',
'index.php?pagename=blog',
'top'
);
add_rewrite_rule(
'^blog/([^/]+)/?$',
'index.php?name=$matches[1]',
'top'
);
}
add_action('init', 'custom_rewrite_rules');
function change_post_type_permalink($post_link, $post) {
if ($post->post_type == 'project') {
return home_url('projeler/' . $post->post_name . '/');
}
return $post_link;
}
add_filter('post_type_link', 'change_post_type_permalink', 10, 2);
function translate_theme_texts($translated_text, $text, $domain) {
$translations = array(
'Home' => 'Anasayfa',
'Projects' => 'Projeler',
'Our Blog' => 'Blog',
'All' => 'Tümü',
'Blog' => 'Blog',
'Read More' => 'Devamını Oku',
'View All' => 'Tümünü Gör',
'Latest Posts' => 'Son Yazılar',
'Recent Posts' => 'Son Yazılar',
'Categories' => 'Kategoriler',
'Tags' => 'Etiketler',
'Search' => 'Arama',
'Contact' => 'İletişim',
'About' => 'Hakkımızda',
'Services' => 'Hizmetler',
'Portfolio' => 'Portföy'
);
if (isset($translations[$text])) {
return $translations[$text];
}
return $translated_text;
}
add_filter('gettext', 'translate_theme_texts', 20, 3);
add_filter('ngettext', 'translate_theme_texts', 20, 3);
function elementor_custom_translations($translated_text, $text, $domain) {
if ($domain === 'elementor' || $domain === 'elementor-pro') {
$elementor_translations = array(
'All' => 'Tümü',
'Home' => 'Anasayfa',
'Projects' => 'Projeler',
'Our Blog' => 'Blog',
'Read More' => 'Devamını Oku',
'View Project' => 'Projeyi Gör',
'Load More' => 'Daha Fazla Yükle'
);
if (isset($elementor_translations[$text])) {
return $elementor_translations[$text];
}
}
return $translated_text;
}
add_filter('gettext', 'elementor_custom_translations', 30, 3);
function add_translation_script() {
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
const translations = {
'Home': 'Anasayfa',
'Projects': 'Projeler',
'Our Blog': 'Blog',
'All': 'Tümü',
'Read More': 'Devamını Oku',
'Load More': 'Daha Fazla Yükle',
'View All': 'Tümünü Gör'
};
function replaceTexts() {
const elements = document.querySelectorAll('*');
elements.forEach(function(element) {
if (element.children.length === 0) {
const text = element.textContent.trim();
if (translations[text]) {
element.textContent = translations[text];
}
}
});
const menuLinks = document.querySelectorAll('nav a, .menu a, .elementor-nav-menu a');
menuLinks.forEach(function(link) {
const text = link.textContent.trim();
if (translations[text]) {
link.textContent = translations[text];
}
});
const filterButtons = document.querySelectorAll('.elementor-portfolio-filter a, .filter-button');
filterButtons.forEach(function(button) {
const text = button.textContent.trim();
if (translations[text]) {
button.textContent = translations[text];
}
});
}
replaceTexts();
if (typeof window.elementorFrontend !== 'undefined') {
window.elementorFrontend.hooks.addAction('frontend/element_ready/global', function() {
setTimeout(replaceTexts, 100);
});
}
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
setTimeout(replaceTexts, 100);
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
</script>
<?php
}
add_action('wp_footer', 'add_translation_script');
function translate_breadcrumbs($text) {
$breadcrumb_translations = array(
'Home' => 'Anasayfa',
'Projects' => 'Projeler',
'Blog' => 'Blog',
'Category' => 'Kategori',
'Tag' => 'Etiket',
'Search Results' => 'Arama Sonuçları'
);
return isset($breadcrumb_translations[$text]) ? $breadcrumb_translations[$text] : $text;
}
function translate_menu_items($items, $menu, $args) {
foreach ($items as $item) {
$menu_translations = array(
'Home' => 'Anasayfa',
'Projects' => 'Projeler',
'Our Blog' => 'Blog',
'Blog' => 'Blog',
'Contact' => 'İletişim',
'About' => 'Hakkımızda'
);
if (isset($menu_translations[$item->title])) {
$item->title = $menu_translations[$item->title];
}
}
return $items;
}
add_filter('wp_nav_menu_objects', 'translate_menu_items', 10, 3);
function flush_rewrite_rules_once() {
if (get_option('custom_rewrite_rules_flushed') !== 'yes') {
flush_rewrite_rules();
update_option('custom_rewrite_rules_flushed', 'yes');
}
}
add_action('init', 'flush_rewrite_rules_once');
function add_translation_css() {
?>
<style>
.elementor-nav-menu a,
.menu a,
.elementor-portfolio-filter a {
font-family: inherit;
letter-spacing: normal;
}
@media (max-width: 768px) {
.elementor-nav-menu a {
font-size: 14px;
}
}
</style>
<?php
}
add_action('wp_head', 'add_translation_css');
function protect_child_theme_functions() {
if (is_child_theme()) {
add_action('upgrader_process_complete', function($upgrader_object, $options) {
if (isset($options['type']) && $options['type'] === 'theme') {
update_option('custom_rewrite_rules_flushed', 'no');
}
}, 10, 2);
}
}
add_action('init', 'protect_child_theme_functions');
?>Yardımı dokunsun hocam , sizden sonra bu sorunu yaşayanlara yardımcı olmuş olur.