最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Looping over an array of URL end points

matteradmin7PV0评论

Hey guys thanks in advance to all, So Iv made a conditional statement for a plugin that runs on woocommerce, to target the URL so I can inject custom css via php or whatever. the code works fine, but I trying to make it cleaner using an array instead of rewriting the statment every time

this is the code hope you guys could help cheers,

//add css if uri contains product base number

add_action('init', 'do_stuff');
function do_stuff()
{
 $url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
 if (false !== strpos($url, 'product_base=22')) {
  echo '<style type="text/css"></style>';
 }
}

this is the array I was thinking about looping over there are two options one with the full path and the other a constant path of product_base with a dynamic number from the array

$product_base = array('product_base=21','product_base=22','product_base=23');

$product_key = array('21','22','23');

cheers again,

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far