title: Wordpress: insert same code with different parameters into multiple pages
body: <p>I'm still a Wordpress newbie, so (hopefully) this is an entirely dumb question. </p>
  
  <p>I need to insert the same embed code (something like this, it's just copied from a visualisation on Tableau Public) (...):</p>
  
  <pre><code>&lt;div class='tableauPlaceholder' id='viz1591173837909' style='position: relative'&gt;&lt;noscript&gt;&lt;a href='http:&amp;#47;&amp;#47;issarfwd.cenia.cz&amp;#47;jihocesky-kraj&amp;#47;ovzdusi&amp;#47;'&gt;&lt;img alt=' ' src='https:&amp;#47;&amp;#47;public.tableau.com&amp;#47;static&amp;#47;images&amp;#47;Kr&amp;#47;Kraje-Ovzdu&amp;#47;Emisnsituace&amp;#47;1_rss.png' style='border: none' /&gt;&lt;/a&gt;&lt;/noscript&gt;&lt;object class='tableauViz'  style='display:none;'&gt;&lt;param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' /&gt; &lt;param name='embed_code_version' value='3' /&gt; &lt;param name='path' value='views&amp;#47;Kraje-Ovzdu&amp;#47;Emisnsituace?:embed=y&amp;amp;:toolbar=yes&amp;amp;:embed_code_version=3&amp;amp;Parameters.Kraj=Jiho%C4%8Desk%C3%BD%20kraj&amp;amp;:loadOrderID=0&amp;amp;:display_count=y?:embed%3Dy' /&gt; &lt;param name='toolbar' value='yes' /&gt;&lt;param name='static_image' value='https:&amp;#47;&amp;#47;public.tableau.com&amp;#47;static&amp;#47;images&amp;#47;Kr&amp;#47;Kraje-Ovzdu&amp;#47;Emisnsituace&amp;#47;1.png' /&gt; &lt;param name='animate_transition' value='yes' /&gt;&lt;param name='display_static_image' value='yes' /&gt;&lt;param name='display_spinner' value='yes' /&gt;&lt;param name='display_overlay' value='yes' /&gt;&lt;param name='display_count' value='yes' /&gt;&lt;param name='filter' value='Parameters.Kraj=Jiho%C4%8Desk%C3%BD%20kraj' /&gt;&lt;/object&gt;&lt;/div&gt;                &lt;script type='text/javascript'&gt;                    var divElement = document.getElementById('viz1591173837909');                    var vizElement = divElement.getElementsByTagName('object')[0];                    vizElement.style.width='1024px';vizElement.style.height='850px';                    var scriptElement = document.createElement('script');                    scriptElement.src = 'https://public.tableau.com/javascripts/api/viz_v1.js';                    vizElement.parentNode.insertBefore(scriptElement, vizElement);                &lt;/script&gt;
  </code></pre>
  
  <p>into several different Wordpress pages within one site. Each time, the embed code should have a different parameter. I chose the parameter to be the subtitle of the page and came up with this code (it works): </p>
  
  <pre><code>if (is_page()) {
  $subtitle = apply_filters( 'plugins/wp_subtitle/get_subtitle', '', array(
     ) );
     if ((strpos($subtitle , 'kraj') == false) &amp;&amp; (strpos($subtitle , 'Praha') == false) &amp;&amp; (strpos($subtitle , 'Vysočina') == false)) {$subtitle = "Všechny kraje";};
   echo
  "&lt;div class='tableauPlaceholder' id='viz1591084101025' style='position: relative'&gt;&lt;noscript&gt;
  &lt;a href='#'&gt;&lt;img alt=' ' src='https:&amp;#47;&amp;#47;public.tableau.com&amp;#47;static&amp;#47;images&amp;#47;Kr&amp;#47;Kraje-Ovzdu&amp;#47;Emisnsituace&amp;#47;1_rss.png' style='border: none' /&gt;
  &lt;/a&gt;&lt;/noscript&gt;&lt;object class='tableauViz'  style='display:none;'&gt;&lt;param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' /&gt; 
  &lt;param name='embed_code_version' value='3' /&gt; &lt;param name='path' value='views&amp;#47;Kraje-Ovzdu&amp;#47;Emisnsituace?:embed=y&amp;amp;:display_count=y' /&gt;
  &lt;param name='filter' value='Parameters.Kraj="  . $query-&gt;post-&gt;post_title . $subtitle . "'&gt;
   &lt;param name='toolbar' value='yes' /&gt;&lt;param name='static_image' value='https:&amp;#47;&amp;#47;public.tableau.com&amp;#47;static&amp;#47;images&amp;#47;Kr&amp;#47;Kraje-Ovzdu&amp;#47;Emisnsituace&amp;#47;1.png' /&gt; &lt;param name='animate_transition' value='yes' /&gt;&lt;param name='display_static_image' value='yes' /&gt;&lt;param name='display_spinner' value='yes' /&gt;&lt;param name='display_overlay' value='yes' /&gt;&lt;param name='display_count' value='yes' /&gt;&lt;/object&gt;&lt;/div&gt;                &lt;script type='text/javascript'&gt;                    var divElement = document.getElementById('viz1591084101025');                    var vizElement = divElement.getElementsByTagName('object')[0];                 
     vizElement.style.width='1024px';vizElement.style.height='850px';                    var scriptElement = document.createElement('script');                    scriptElement.src = 'https://public.tableau.com/javascripts/api/viz_v1.js';                    vizElement.parentNode.insertBefore(scriptElement, vizElement);                &lt;/script&gt;";}?&gt; ```
  </code></pre>
  
  <p>The embed code (=in quotes above) is messy, so just to highlight the single thing I changed inside it:</p>
  
  <p><code>&lt;param name='filter' value='Parameters.Kraj="  . $query-&gt;post-&gt;post_title . $subtitle . "'&gt;</code></p>
  
  <p>I would like to insert something like the above into a page template, so that I don't have to insert the slightly changed code into every page individually. </p>
  
  <p>The question is: where should I load the embed code from? If it changes, I would like people to be able to edit it from the admin area. This should be a single place: a user pastes it in there → it gets read by the page template → the code gets changed in any page that has this template. Could this maybe be done from a page that won't be made public? Any other tips?</p>
  
  <p>Thanks a lot!</p>