简体   繁体   中英

Change PHP Shortcode depending on anchor tag in URL

Wanting to change a shortcode based off what the URL's anchor is displaying. So for example (In pseudo code) :

<?php
 if(url="/example-page#anchor1") {
   echo do_shortcode('[example_shortcode_1]')
 }

 if(url="/example-page#anchor2") {
   echo do_shortcode('[example_shortcode_2]')
 }

 if(url="/example-page#anchor3") {
   echo do_shortcode('[example_shortcode_3]')
 }
?>

Any idea on how I could possibly do this? I CAN do it in jQuery/JS if PHP is not possible.

As mentioned, I would probably parse the hash client-side location.hash , and then send that value server-side via jQuery, then run your short-code and dynamically populate the needed area. If you are doing anything more complex than that, then as @NappingRabit stated, you should probably make multiple pages.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM