PHP: How to Check if a String Exists in a URL

For one of the sites I was working on, I had to create a multilingual site for English and French where the English version would use the English logo and the French site would use the French logo. The plugin I used allowed me to have both English and French versions on a single WordPress installation. But, the one challenge I had was working around the base theme’s Theme Options settings where I could only specific one logo file.

I found the answer on stackoverflow and I wanted to share the solution I found and I how I implemented it to solve my problem.

The first step is to build the URL string into a variable then use strpos() function to check if a string exists and do what you need to do as in the example below where they’re checking to see if the word, “car”, exists in the URL:

To fix my problem, I simply changed the echo statement to output the theme’s settings to display the logo selected in the Theme Options and echoed the image tag with the French logo.

I hope this helped you as it did and worked for me.

 

Tags

Leave a Reply

Your email address will not be published.

top