My url is www.mysite.com/properties/property-1-someplace
The /property-1-someplace/
is dynamically generated.
I'm writing an if statement that asks if the url is properties/property-1-someplace
then execute code, but property-1-someplace
is generated by wordpress and thus is constantly changing.
How can I target pages that are in the properties directory, but access the url afterwards if I don't know what that url is?
I can use the PHP variable $pagename
but that does not address the properties
part of the url.
If I could do <?php if (is_page( 'property/*.*' ) ):
that would be perfect.
Any ideas?
EDIT:
Sorry I misunderstood your question, here is what you are probably looking for. Note that you may have to change the regular expression pattern to /^properties/
depending on the value of $pagename
. If $pagename
contains the whole URL (eg with domain name) then you will need to update the code with the domain name.
if( preg_match( '/^\/properties/', $pagename ) ) {
// Do your stuff here.
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.