Untitled
raw download clone
PHP
views 31
,
size 1083 b
<?php
















// Run action when post draft to publish
add_action ('draft_to_publish', 'title_rename');
















// Function with synonymouse replacement
function title_rename() {
















  // Get post title to string
  // --> I don't know how <--
  $title = 'Beautiful vehicle';
















  // Convert title to lowercase
  $lowTitle = mb_convert_case($title, MB_CASE_LOWER, "UTF-8");
















  // Synonymous for replace
  $synonymous = array(
    'beautiful' => 'perect',
    'vehicle' => 'car',
  );
















  // Loop with word check and replace
  foreach ($synonymous as $key => $value) {
    
    if(is_string($key)) { 
      $stringKey = $key;
















      // Replace in title
      if (strpos($lowTitle, $stringKey) !== false) {  
        $lowTitle = str_replace($stringKey, $value, $lowTitle);
      }
    }
  }
  // Save new title and slug
}
close fullscreen
Login or Register to edit or fork this paste. It's free.