Created
December 14, 2023 19:30
-
-
Save Edwardtonnn/3b8676d44ea3c4b22d876d11fc6b2e57 to your computer and use it in GitHub Desktop.
Removes duplicates from SEO Title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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