Peter Knight Posted April 21, 2017 Share Posted April 21, 2017 <?php if ($page->path == "/blog/posts/"){ echo "<script type='text/javascript' src='//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-55e5693b9add30c6'></script>"; } ?> I'm trying to output a script on my blog posts only. They're all children of /blog/posts/ so I thought the above might work. That seems to work only when the page loaded is exactly /blog/posts/ How can I tweak this to work on any page containing /blog/posts/ in it's URL / path and not just /blog/posts/ ? I've been to the API and tried a few variations using the following if ($page->path *= "/blog/posts/") but I think they're more selectors for fields? Link to comment Share on other sites More sharing options...
ukyo Posted April 21, 2017 Share Posted April 21, 2017 You can use strpos() function Link to comment Share on other sites More sharing options...
abdus Posted April 21, 2017 Share Posted April 21, 2017 You can use strpos() function <?php if (strpos($page->path, "/blog/posts/") === 0){ echo "..."; } ?> Link to comment Share on other sites More sharing options...
Zeka Posted April 21, 2017 Share Posted April 21, 2017 if($page->matches("has_parent=/blog/posts/")) { } 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now