{"id":4297,"date":"2022-08-22T05:47:43","date_gmt":"2022-08-22T00:17:43","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/"},"modified":"2022-08-22T05:47:43","modified_gmt":"2022-08-22T00:17:43","slug":"solved-dynamic-html-not-displaying-at-respective-place","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/","title":{"rendered":"[Solved] Dynamic HTML not displaying at respective place"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-351692\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"351692\" data-parentid=\"351688\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>You&#8217;re getting the output there because <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.wordpress.org\/reference\/functions\/dynamic_sidebar\/\"><code>dynamic_sidebar()<\/code><\/a> displays\/echoes the output (widgets in the specific sidebar), so the output is echoed right when the shortcode function is called, which is before the <code>$data<\/code> is actually echoed.<\/p>\n<p>And you can fix that using <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/stackoverflow.com\/q\/2832010\">output buffering<\/a>:<\/p>\n<ol>\n<li>\n<p>Either append the output to <code>$data<\/code>:<\/p>\n<pre class=\"lang-php prettyprint-override\"><code>$data.='&lt;\/div&gt;';\n$data.='&lt;div class=\"col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12\"&gt;&lt;div class=\"cp-social\"&gt;';\nif (is_active_sidebar('footer-social')) :\n    ob_start();\n    dynamic_sidebar('footer-social'); \/\/ echoes the widgets\n    $data .= ob_get_clean();          \/\/ append the output\nendif;\n$data.='&lt;\/div&gt;&lt;div class=\"cp-newsletter\"&gt;';\nif (is_active_sidebar('cp_newsletter')) :\n    ob_start();\n    dynamic_sidebar('cp_newsletter'); \/\/ echoes the widgets\n    $data .= ob_get_clean();          \/\/ append the output\nendif;\n$data.='&lt;\/div&gt;&lt;\/div&gt;&lt;\/div&gt;&lt;\/div&gt;&lt;\/div&gt;';\n<\/code><\/pre>\n<p>You can turn on\/off output buffering at anytime, and you should do the same as above with the <code>cp_newsletter<\/code> sidebar.<\/p>\n<p><strong><em>Update:<\/em><\/strong> Not sure why this option is not working for you, but maybe the updated code can help?<\/p>\n<\/li>\n<li>\n<p>Or (maybe easier), echo everything in your function:<\/p>\n<pre class=\"lang-php prettyprint-override\"><code>function Post_home() {\n    ob_start();\n    ?&gt;\n        &lt;div class=\"cp-seeWrapper\"&gt;\n          &lt;div class=\"container\"&gt;\n            &lt;div class=\"row\"&gt;\n              &lt;div class=\"col-xl-8 col-lg-8 col-md-8 col-sm-12 col-xs-12\"&gt;\n              &lt;\/div&gt;\n              &lt;div class=\"col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12\"&gt;\n                &lt;div class=\"cp-social\"&gt;\n                  &lt;?php if ( is_active_sidebar( 'social-footer' ) ) dynamic_sidebar( 'social-footer' ); ?&gt;\n                &lt;\/div&gt;\n                &lt;div class=\"cp-newsletter\"&gt;\n                  &lt;?php if ( is_active_sidebar( 'cp_newsletter' ) ) dynamic_sidebar( 'cp_newsletter' ); ?&gt;\n                &lt;\/div&gt;\n              &lt;\/div&gt;\n            &lt;\/div&gt;\n          &lt;\/div&gt;\n        &lt;\/div&gt;\n    &lt;?php\n    return ob_get_clean();\n}\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2>UPDATE<\/h2>\n<p>For option #1, you might want to consider caching either the widgets (i.e. the output returned by the <code>ob_get_clean()<\/code> call) or your shortcode output (i.e. the entire content of the <code>$data<\/code>). I suggested that for performance reasons where the shortcode <em>could<\/em> be called twice or more on the same page.<\/p>\n<p>Additionally, if you&#8217;re going to use option #2 (echo everything), then you might want to consider creating a template and do something like:<\/p>\n<pre class=\"lang-php prettyprint-override\"><code>function Post_home() {\n    ob_start();\n    locate_template( 'my-template.php', true );\n    return ob_get_clean();\n}\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">5<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Dynamic HTML not displaying at respective place <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] You&#8217;re getting the output there because dynamic_sidebar() displays\/echoes the output (widgets in the specific sidebar), so the output is echoed right when the shortcode function is called, which is before the $data is actually echoed. And you can fix that using output buffering: Either append the output to $data: $data.='&lt;\/div&gt;&#8217;; $data.='&lt;div class=&#8221;col-xl-4 col-lg-4 col-md-4 &#8230; <a title=\"[Solved] Dynamic HTML not displaying at respective place\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/\" aria-label=\"More on [Solved] Dynamic HTML not displaying at respective place\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[627],"tags":[682,745,647],"class_list":["post-4297","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-plugins","tag-posts","tag-shortcode"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Dynamic HTML not displaying at respective place - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Dynamic HTML not displaying at respective place - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] You&#8217;re getting the output there because dynamic_sidebar() displays\/echoes the output (widgets in the specific sidebar), so the output is echoed right when the shortcode function is called, which is before the $data is actually echoed. And you can fix that using output buffering: Either append the output to $data: $data.=&#039;&lt;\/div&gt;&#039;; $data.=&#039;&lt;div class=&quot;col-xl-4 col-lg-4 col-md-4 ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-22T00:17:43+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Dynamic HTML not displaying at respective place\",\"datePublished\":\"2022-08-22T00:17:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/\"},\"wordCount\":185,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"plugins\",\"posts\",\"shortcode\"],\"articleSection\":[\"WordPress\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/\",\"name\":\"[Solved] Dynamic HTML not displaying at respective place - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-08-22T00:17:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Dynamic HTML not displaying at respective place\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Dynamic HTML not displaying at respective place - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Dynamic HTML not displaying at respective place - JassWeb","og_description":"[ad_1] You&#8217;re getting the output there because dynamic_sidebar() displays\/echoes the output (widgets in the specific sidebar), so the output is echoed right when the shortcode function is called, which is before the $data is actually echoed. And you can fix that using output buffering: Either append the output to $data: $data.='&lt;\/div&gt;'; $data.='&lt;div class=\"col-xl-4 col-lg-4 col-md-4 ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/","og_site_name":"JassWeb","article_published_time":"2022-08-22T00:17:43+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Dynamic HTML not displaying at respective place","datePublished":"2022-08-22T00:17:43+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/"},"wordCount":185,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["plugins","posts","shortcode"],"articleSection":["WordPress"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/","url":"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/","name":"[Solved] Dynamic HTML not displaying at respective place - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-08-22T00:17:43+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-dynamic-html-not-displaying-at-respective-place\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Dynamic HTML not displaying at respective place"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/4297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=4297"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/4297\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=4297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=4297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=4297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}