0

I need to add meta lines to the header.php only where the page url contains /200/

We are currently using this rule:

<?php if($page == 200) { ?>
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="robots" content="noindex, nofollow" /> 
<?php } ?>

Error log gives an error for this patch: [Tue Mar 12 13:13:15.070693 2019] [:error] [pid 28413] [client 127.0.0.1:29570] PHP Notice: Undefined variable: page in /nas/content/live/parentsdome1/wp-content/themes/voice/header.php on line 27

I have a local JS parameter called page_number

Can I use that somehow instead?

Other ideas on how to 'query' the string to see if it contains "/200/"?

Many thanks!

2

1 Answer 1

2

You can do it only with PHP.

First get the current URL, then check if it contains a specific string.

<?php
    $page = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'
        ? "https"
        : "http")
        . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

    if (strpos($page, '/200/') !== false):
?>

<!-- <meta> -->

<?php
    endif;
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.