• I am looking for a way to syndicate different website pages but also have some words changed based on the root of the URL. For example I want to update one page and it will automatically update all the other pages but I want all the anchor links within the page link to link to the website it is on (https://examplespokane.com & https://exampleseattle.com). Is there a code I can implement that would allow me to do this? I want the anchor links to automatically grab the location part of the URL so the links will still work with the page but I don’t have to go to each individual page to change it. Is there a plugin that would allow me to do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Are you really going to buy and register different domain names for every location? Some may already be taken. Why not use subdomains, they’re usually free up to a point? For example spokane.example.com or seattle.example.com. Simpler would be to use the same domain and alter the URL: example.com/pagename/spokane/. The simplest would be to pass the location as a query string: example.com/?city=spokane.

    Whichever approach you use, PHP can extract such data from the URL, either from $_SERVER or $_REQUEST and use it in generating page output. This can be done via template code, shortcode, or custom block, depending on where you want the passed name to occur in content.

    I’m not aware of such a plugin, but that doesn’t mean one does not exist. I tried searching https://www.ads-software.com/plugins/search/dynamic+content/ but only a few of the many results sounded promising.

    • This reply was modified 2 years, 4 months ago by bcworkz. Reason: corrected var names
    Thread Starter kflow0

    (@kflow0)

    How would the code go for that? @bcworkz

    Moderator bcworkz

    (@bcworkz)

    Going with the simplest solution (URL query string), roughly something like:

    // replaces "%%cityname%%" in any post content with passed 'city' value from URL
    add_filter('the_content', 'kfl_merge_city_name');
    function kfl_merge_city_name( $content ) {
      if ( array_key_exists( 'city', $_REQUEST )) {
        $city = $_REQUEST['city'];
        // must add code to validate, sanitize, and escape $city here
        $content = str_replace('%%cityname%%', $city, $content );
      }
      return $content;
    }

    Incomplete and untested, but that’s the gist of it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Page Syndication’ is closed to new replies.