{"id":1200,"date":"2023-10-26T13:00:42","date_gmt":"2023-10-26T13:00:42","guid":{"rendered":"https:\/\/wpshortcode.org\/?p=1200"},"modified":"2023-10-26T13:00:43","modified_gmt":"2023-10-26T13:00:43","slug":"custom-post-widget","status":"publish","type":"post","link":"https:\/\/wpshortcode.org\/custom-post-widget\/","title":{"rendered":"Content Blocks (Custom Post Widget) Shortcode"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Below, you&#8217;ll find a detailed guide on how to add the <strong>Content Blocks (Custom Post Widget) Shortcode<\/strong> to your WordPress website, including its <strong>parameters<\/strong>, <strong>examples<\/strong>, and <strong>PHP function code<\/strong>. Additionally, we&#8217;ll assist you with common issues that might cause the Content Blocks (Custom Post Widget) Plugin shortcode not to show or not to work correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before starting, here is an overview of the Content Blocks (Custom Post Widget) Plugin and the shortcodes it provides:<\/p>\n\n\n<p>    <div class=\"plugin-info-box\">\n        <div class=\"top-main\">\n            <!-- SVG Image -->\n            <div class=\"plugin-image\">\n                <img decoding=\"async\" src=\"https:\/\/ps.w.org\/custom-post-widget\/assets\/icon.svg?rev=2884166\" alt=\"Plugin Icon\" \/>\n            <\/div>\n            \n            <div class=\"plugin-descriptive-part\">\n                <!-- Plugin Name with Link -->\n\n                    <a class=\"plugin-title\" href=\"https:\/\/wordpress.org\/plugins\/custom-post-widget\" target=\"_blank\" rel=\"noopener\">\n                        Content Blocks (Custom Post Widget)                    <\/a>\n\n\n                <!-- Plugin Description -->\n                <p class=\"plugin-description\">\n                    &quot;Content Blocks (Custom Post Widget) is a handy WordPress plugin that lets you create reusable widget content from your posts. You can display these blocks anywhere on your site.&quot;                <\/p>\n            <\/div>\n        <\/div>\n\n        <!-- Rating and Additional Info -->\n        <div class=\"plugin-meta\">\n            <span class=\"plugin-rating\">\n                <span class='stars'>\u2605\u2605\u2605\u2605\u2606<\/span> (76)\n            <\/span>\n            <span class=\"plugin-active-installs\">\n                <strong>Active Installs<\/strong>: 20000+\n            <\/span>\n            <span class=\"plugin-tested\">\n                <strong>Tested with<\/strong>: 6.3.2            <\/span>\n            <span class=\"plugin-php-version\">\n                <strong>PHP Version<\/strong>: false            <\/span>\n        <\/div>\n\n        <!-- List of Included Shortcodes -->\n        <div class=\"plugin-shortcodes\">\n            <strong>Included Shortcodes:<\/strong>\n            <ul>\n                <li>[content_block]<\/li>            <\/ul>\n        <\/div>\n    <\/div>\n    <\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Content Blocks (Custom Post Widget) [content_block] Shortcode<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The &#8216;content_block&#8217; shortcode from the Custom Post Widget plugin is used to display a custom post or content block on your site. \n\n\n\nThis shortcode accepts several parameters like &#8216;id&#8217;, &#8216;slug&#8217;, &#8216;class&#8217;, etc. If a &#8216;slug&#8217; is provided, it fetches the content block with that slug. It also allows for customization of the output through a template file. \n\nThe content can include the post title, featured image, and the post content itself, based on the parameters set. The output is wrapped in a specified HTML tag with a class for easy styling.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode<\/strong>: <code>[content_block]<\/code><\/p>\n\n\n\n<div style=\"height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Parameters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a list of all possible content_block shortcode parameters and attributes:<\/p>\n\n\n<ul>\n<li><code>id<\/code> &#8211; Unique identifier of the content block.<\/li>\n<li><code>slug<\/code> &#8211; URL-friendly version of the content block&#8217;s name.<\/li>\n<li><code>class<\/code> &#8211; CSS class applied to the content block.<\/li>\n<li><code>suppress_content_filters<\/code> &#8211; Determines if content filters are applied. &#8216;no&#8217; applies filters.<\/li>\n<li><code>featured_image<\/code> &#8211; If set to &#8216;yes&#8217;, the featured image of the content block is displayed.<\/li>\n<li><code>featured_image_size<\/code> &#8211; Defines the size of the featured image. Default is &#8216;medium&#8217;.<\/li>\n<li><code>title<\/code> &#8211; If &#8216;yes&#8217;, the content block&#8217;s title is displayed.<\/li>\n<li><code>title_tag<\/code> &#8211; HTML tag used for the content block&#8217;s title. Default is &#8216;h3&#8217;.<\/li>\n<li><code>markup<\/code> &#8211; The HTML tag used to wrap the content block. Default is &#8216;div&#8217;.<\/li>\n<li><code>template<\/code> &#8211; Name of the template file used for displaying the content block.<\/li>\n<\/ul>\n\n\n<div style=\"height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Examples and Usage<\/h3>\n\n\n<p><strong>Basic example<\/strong> &#8211; Display a content block by referencing its ID<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[content_block id=\"123\" \/]<\/code><\/pre>\n\n\n<p><strong>Advanced examples<\/strong><\/p>\n<p>Display a content block by referencing its slug. This is useful when you want to reference a block by its name instead of its ID.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[content_block slug=\"my-custom-block\" \/]<\/code><\/pre>\n\n\n<p>Display a content block with a custom CSS class. This can be useful for styling the block in a specific way.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[content_block id=\"123\" class=\"my-custom-class\" \/]<\/code><\/pre>\n\n\n<p>Display a content block with its featured image. This can be useful for blocks that contain a featured image you want to display.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[content_block id=\"123\" featured_image=\"yes\" \/]<\/code><\/pre>\n\n\n<p>Display a content block with its title. This can be useful for blocks where you want to display the title of the block.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[content_block id=\"123\" title=\"yes\" \/]<\/code><\/pre>\n\n\n<p>Suppress content filters for a content block. This can be useful for blocks where you want to display the raw content without any WordPress filters being applied.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[content_block id=\"123\" suppress_content_filters=\"yes\" \/]<\/code><\/pre>\n\n\n<p>Display a content block using a specific template. This can be useful for blocks where you want to use a custom template to display the block.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[content_block id=\"123\" template=\"my-custom-template.php\" \/]<\/code><\/pre>\n\n\n\n<div style=\"height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">PHP Function Code<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In case you have difficulties debugging what causing issues with <code>[content_block]<\/code> shortcode, check below the related PHP functions code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode line<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_shortcode( 'content_block', 'custom_post_widget_shortcode' );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode PHP function<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; light: false; title: ; toolbar: true; notranslate\" title=\"\">\nfunction custom_post_widget_shortcode( $atts ) {\n\t$params = shortcode_atts( array(\n\t\t&#039;id&#039; =&gt; &#039;&#039;,\n\t\t&#039;slug&#039; =&gt; &#039;&#039;,\n\t\t&#039;class&#039; =&gt; &#039;content_block&#039;,\n\t\t&#039;suppress_content_filters&#039; =&gt; &#039;no&#039;,\n\t\t&#039;featured_image&#039; =&gt; &#039;no&#039;,\n\t\t&#039;featured_image_size&#039; =&gt; &#039;medium&#039;,\n\t\t&#039;title&#039; =&gt; &#039;no&#039;,\n\t\t&#039;title_tag&#039; =&gt; &#039;h3&#039;,\n\t\t&#039;markup&#039; =&gt; &#039;div&#039;,\n\t\t&#039;template&#039; =&gt; &#039;&#039;\n\t), $atts );\n\n\t$id = $params&#91;&#039;id&#039;];\n\t$slug = $params&#91;&#039;slug&#039;];\n\t$class = $params&#91;&#039;class&#039;];\n\t$suppress_content_filters = $params&#91;&#039;suppress_content_filters&#039;];\n\t$featured_image = $params&#91;&#039;featured_image&#039;];\n\t$featured_image_size = $params&#91;&#039;featured_image_size&#039;];\n\t$title = $params&#91;&#039;title&#039;];\n\t$title_tag = $params&#91;&#039;title_tag&#039;];\n\t$markup = $params&#91;&#039;markup&#039;];\n\t$template = $params&#91;&#039;template&#039;];\n\n\tif ( $slug ) {\n\t\t$block = get_page_by_path( $slug, OBJECT, &#039;content_block&#039; );\n\t\tif ( $block ) {\n\t\t\t$id = $block-&gt;ID;\n\t\t}\n\t}\n\n\t$content = &quot;&quot;;\n\n\t\/\/ Attempt to load a template file\n\tif ( $params&#91;&#039;template&#039;] != &#039;&#039; ) {\n\t\tif ( $located = locate_template( $params&#91;&#039;template&#039;] ) ) {\n\t\t\tinclude_once $located;\n\t\t}\n\t}\n\n\tif ( $id != &quot;&quot; ) {\n\n\t\t$args = array(\n\t\t\t&#039;post__in&#039; =&gt; array( $id ),\n\t\t\t&#039;post_type&#039; =&gt; &#039;content_block&#039;,\n\t\t);\n\n\t\t$content_post = get_posts( $args );\n\n\t\tforeach( $content_post as $post ) :\n\n\t\t\tif ( isset( $located ) ) {\n\t\t\t\t\/\/ Template-based content\n\t\t\t\t$content .= call_user_func( &#039;shortcode_template&#039;, $post );\n\n\t\t\t} else {\n\t\t\t\t\/\/ Standard format content\n\t\t\t\t$content .= &#039;&lt;&#039; . esc_attr( $markup ) . &#039; class=&quot;&#039;. esc_attr( $class ) .&#039;&quot; id=&quot;custom_post_widget-&#039; . $id . &#039;&quot;&gt;&#039;;\n\t\t\t\tif ( $title === &#039;yes&#039; ) {\n\t\t\t\t\t$content .= &#039;&lt;&#039; . esc_attr( $title_tag ) . &#039;&gt;&#039; . $post -&gt; post_title . &#039;&lt;\/&#039; . esc_attr( $title_tag ) . &#039;&gt;&#039;;\n\t\t\t\t}\n\t\t\t\tif ( $featured_image === &#039;yes&#039; ) {\n\t\t\t\t\t$content .= get_the_post_thumbnail( $post -&gt; ID, $featured_image_size );\n\t\t\t\t}\n\t\t\t\tif ( $suppress_content_filters === &#039;no&#039; ) {\n\t\t\t\t\t$content .= apply_filters( &#039;the_content&#039;, $post -&gt; post_content );\n\t\t\t\t} else {\n\t\t\t\t\t$content .= $post -&gt; post_content;\n\t\t\t\t}\n\t\t\t\t$content .= &#039;&lt;\/&#039; .  esc_attr( $markup ) . &#039;&gt;&#039;;\n\t\t\t}\n\t\tendforeach;\n\n\t}\n\n\treturn $content;\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Code file location<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">custom-post-widget\/custom-post-widget\/shortcode.php<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you&#8217;ve learned how to embed the <strong>Content Blocks (Custom Post Widget) Plugin shortcode<\/strong>, understood the parameters, and seen code examples, it&#8217;s easy to use and debug any issue that might cause it to &#8216;not work&#8217;. If you still have difficulties with it, don&#8217;t hesitate to leave a comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below, you&#8217;ll find a detailed guide on how to add the Content Blocks (Custom Post Widget) Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we&#8217;ll assist you with common issues that might cause the Content Blocks (Custom Post Widget) Plugin shortcode not to show or not to work correctly. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"name":"Content Blocks (Custom Post Widget)","slug":"","version":"3.2.6","author":"<a href=\"https:\/\/vanderwijk.nl\">Johan van der Wijk<\/a>","icons":"https:\/\/ps.w.org\/custom-post-widget\/assets\/icon.svg?rev=2884166","plugin_tags":"{\"block\":\"block\",\"content-block\":\"content block\",\"custom\":\"custom\",\"sidebar\":\"sidebar\",\"widget\":\"widget\"}","author_profile":"https:\/\/profiles.wordpress.org\/vanderwijk\/","requires":"4.0","tested":"6.3.2","requires_php":"false","rating":98,"num_ratings":76,"active_installs":20000,"downloaded":579300,"last_updated":"2023-07-24 1:19pm GMT","added":"2010-11-15","homepage":"https:\/\/vanderwijk.com\/wordpress\/wordpress-custom-post-widget\/?utm_source=wordpress&utm_medium=plugin&utm_campaign=custom_post_widget","short_description":"This plugin enables you to edit and display Content Blocks in a sidebar widget or using a shortcode.","description":"\"Content Blocks (Custom Post Widget) is a handy WordPress plugin that lets you create reusable widget content from your posts. You can display these blocks anywhere on your site.\"","shortcodes":"[\"content_block\"]","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1200","post","type-post","status-publish","format-standard","hentry","category-plugins"],"_links":{"self":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/1200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/comments?post=1200"}],"version-history":[{"count":1,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/1200\/revisions"}],"predecessor-version":[{"id":1462,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/1200\/revisions\/1462"}],"wp:attachment":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/media?parent=1200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/categories?post=1200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/tags?post=1200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}