Wordpress Only run code if on a certain page

I have a wordpress site and some custom code that I only what to run if the post is part of a Series.
So my address http://www.MYSITE.com/series/interesting-facts

I want the custom code to run when I am in "Series".  How do I do that?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Custom PHP code?

You probably looking for the is_page() function

if (is_page('interesting-facts')) {
  // Do something awesome here

Open in new window

Julian HansenCommented:
After re-reading the question I don't think this will work.

I am assuming you are using a plugin to manage your series? Which one?
rgranlundAuthor Commented:
I'm not using a plugin.
But the above is not correct, what I mean is:
if (is_page('series')) {
  // Do something awesome here

Can I do that?  Using that part of the URL?
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Julian HansenCommented:
No - the is_page only works on the name of the page - series would be common to all pages.

How have you implemented your pages in your series?
KimputerIT ManagerCommented:
Use $_SERVER['REQUEST_URI'], check that the first part is '/series'
Just make sure those pages are based on a template (and have the template contain the PHP code).
rgranlundAuthor Commented:
The template is taxonomy-series.php per the wordpress instructions.  For somereason I can't get it to work by the template name.

Use $_SERVER['REQUEST_URI'], check that the first part is '/series' -- How do I write that?
KimputerIT ManagerCommented:

if (substr($_SERVER['REQUEST_URI'], 0, 7) == '/series') {

//code here
Julian HansenCommented:
The $_SERVER approach will most likely work but I am interested to see what the WP way of doing this is.

If you put this code into taxonomy-series.php - what do you get
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 
echo "<pre>" . print_r($term, true) . "</pre>"; ?>

Open in new window

rgranlundAuthor Commented:
AH!  Also, I know this is not recomended but can y'all look at this question?
rgranlundAuthor Commented:
WP_Term Object
    [term_id] => 16
    [name] => Serie 1
    [slug] => serie-1
    [term_group] => 0
    [term_taxonomy_id] => 16
    [taxonomy] => series
    [description] =>
    [parent] => 0
    [count] => 1
    [filter] => raw
    [term_order] => 0
Julian HansenCommented:
Ok - so you can try checking for
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
if ($term['taxonomy'] == 'series') {
   // good to go here

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.