Skip to content

Instantly share code, notes, and snippets.

@Edwardtonnn
Created December 14, 2023 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Edwardtonnn/3b8676d44ea3c4b22d876d11fc6b2e57 to your computer and use it in GitHub Desktop.
Save Edwardtonnn/3b8676d44ea3c4b22d876d11fc6b2e57 to your computer and use it in GitHub Desktop.
Removes duplicates from SEO Title
# Define the path to the root of your PHP projects
$rootPath = "./"
# Define the file pattern to search for
$filePattern = "*.php"
# Function to fix the SEO title in a file
function Fix-SeoTitle {
param (
[string]$filePath
)
try {
# Read the file content
$content = Get-Content $filePath -Raw
# Regex pattern to find duplicated SEO title
$pattern = '\$seotitle = "(.*? - Park, Chris \(mprsd\.com\))\1";'
if ($content -match $pattern) {
# Replace the duplicated part with a single occurrence
$fixedContent = $content -replace $pattern, '$seotitle = "$1";'
# Write the fixed content back to the file
Set-Content -Path $filePath -Value $fixedContent
Write-Host "Fixed file: $filePath"
}
}
catch {
Write-Host "Error processing file: $filePath"
}
}
# Find all PHP files and apply the fix
Get-ChildItem -Path $rootPath -Filter $filePattern -Recurse | ForEach-Object {
Fix-SeoTitle -filePath $_.FullName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment