{"id":1819,"date":"2023-11-09T21:46:30","date_gmt":"2023-11-09T21:46:30","guid":{"rendered":"https:\/\/wpshortcode.org\/?p=1819"},"modified":"2023-11-09T21:46:30","modified_gmt":"2023-11-09T21:46:30","slug":"anspress-question-answer","status":"publish","type":"post","link":"https:\/\/wpshortcode.org\/anspress-question-answer\/","title":{"rendered":"AnsPress Shortcodes"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Below, you&#8217;ll find a detailed guide on how to add the <strong>AnsPress \u2013 Question and answer Shortcodes<\/strong> to your WordPress website, including their <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 AnsPress \u2013 Question and answer Plugin shortcodes 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 AnsPress \u2013 Question and answer 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\/anspress-question-answer\/assets\/icon-128x128.png?rev=2432843\" 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\/anspress-question-answer\" target=\"_blank\" rel=\"noopener\">\n                        AnsPress &#8211; Question and answer                    <\/a>\n\n\n                <!-- Plugin Description -->\n                <p class=\"plugin-description\">\n                    &quot;AnsPress &#8211; Question and Answer is a dynamic WordPress plugin perfect for creating interactive Q&amp;A forums on your site. With this, engage your audience in thoughtful discussions.&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\u2729<\/span> (98)\n            <\/span>\n            <span class=\"plugin-active-installs\">\n                <strong>Active Installs<\/strong>: 4000+\n            <\/span>\n            <span class=\"plugin-tested\">\n                <strong>Tested with<\/strong>: 6.2.3            <\/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>[apcode]<\/li><li>[anspress]<\/li><li>[question]<\/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\">AnsPress [apcode] Shortcode<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The AnsPress Question-Answer plugin shortcode is a tool that formats the display of code snippets. It uses the &#8216;apcode&#8217; shortcode to parse the attributes and content.\nIt allows customization of language and inline display. The content is stripped of break tags and class attributes are added based on the language selected. It replaces the &#8216;<pre' and '<code' tags with the class attributes, enhancing readability.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode<\/strong>: <code>[apcode]<\/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 apcode shortcode parameters and attributes:<\/p>\n\n\n<ul>\n<li><code>language<\/code> &#8211; Specifies the programming language for syntax highlighting.<\/li>\n<li><code>inline<\/code> &#8211; Determines whether the code is displayed inline or as a 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; The following shortcode is a simple usage of the &#8216;apcode&#8217; shortcode. It applies the default &#8216;plain&#8217; language setting and does not apply the &#8216;inline&#8217; attribute.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[apcode \/]<\/code><\/pre>\n\n\n<p><strong>Advanced examples<\/strong><\/p>\n<p>Here, we use the &#8216;apcode&#8217; shortcode to specify the language attribute. This example sets the language to &#8216;php&#8217;, which might be useful when displaying code snippets in a PHP context. The &#8216;inline&#8217; attribute is also set to &#8216;true&#8217;, which means the code will be displayed in an inline format.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[apcode language=\"php\" inline=\"true\" \/]<\/code><\/pre>\n\n\n<p>In this next advanced example, we use the &#8216;apcode&#8217; shortcode with the &#8216;language&#8217; attribute set to &#8216;javascript&#8217; and the &#8216;inline&#8217; attribute set to &#8216;false&#8217;. This could be useful for displaying JavaScript code blocks in a non-inline format.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[apcode language=\"javascript\" inline=\"false\" \/]<\/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>[apcode]<\/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( 'apcode', array( $this, '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 shortcode( $atts, $content = &#039;&#039; ) {\n\t\t$atts = wp_parse_args(\n\t\t\t$atts,\n\t\t\tarray(\n\t\t\t\t&#039;language&#039; =&gt; &#039;plain&#039;,\n\t\t\t\t&#039;inline&#039;   =&gt; false,\n\t\t\t)\n\t\t);\n\n\t\t$tag     = $atts&#91;&#039;inline&#039;] ? &#039;code&#039; : &#039;pre&#039;;\n\t\t$content = preg_replace( &#039;\/&lt;br(\\s+)?\\\/?&gt;\/i&#039;, &#039;&#039;, $content );\n\t\t$klass   = &#039;class=&quot;brush: &#039; . esc_attr( $atts&#91;&#039;language&#039;] ) . &#039;&quot;&#039;;\n\t\t$content = str_replace( array( &#039;&lt;pre&#039;, &#039;&lt;code&#039; ), array( &#039;&lt;pre &#039; . $klass, &#039;&lt;code &#039; . $klass ), $content );\n\n\t\treturn $content;\n\t}\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\">anspress-question-answer\/anspress-question-answer\/addons\/syntaxhighlighter\/syntaxhighlighter.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\">AnsPress [anspress] Shortcode<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The AnsPress BasePage shortcode is a versatile tool for WordPress. It enables the AnsPress Question-Answer plugin to function on a page, allowing users to ask and answer questions. \n\n \n\nThis shortcode includes important scripts and styles necessary for the plugin&#8217;s operation. It also prevents nesting of the shortcode and provides a link back to the author, if required.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode<\/strong>: <code>[anspress]<\/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\">Examples and Usage<\/h3>\n\n\n<p><strong>Basic example<\/strong> &#8211; The AnsPress shortcode is utilized to display the AnsPress question and answer section on a page.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[anspress \/]<\/code><\/pre>\n\n\n<p><strong>Advanced examples<\/strong><\/p>\n<p>Utilizing the AnsPress shortcode with additional parameters to customize the output. In this example, we&#8217;re specifying a page attribute to define which AnsPress page should be displayed.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[anspress page=\"questions\" \/]<\/code><\/pre>\n\n\n<p>Another example of using the AnsPress shortcode with multiple parameters. Here, we&#8217;re specifying both a page and an order_by attribute to customize the output. The page attribute defines which AnsPress page should be displayed, and the order_by attribute determines the order in which the questions are listed.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[anspress page=\"questions\" order_by=\"votes\" \/]<\/code><\/pre>\n\n\n<p>Please note that the actual parameters available for the AnsPress shortcode may vary depending on the version of the AnsPress plugin you are using, and the specific configuration of your WordPress site. Always refer to the AnsPress documentation for the most accurate and up-to-date information.<\/p>\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>[anspress]<\/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( 'anspress', array( AnsPress_BasePage_Shortcode::get_instance(), 'anspress_sc' ) );<\/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 anspress_sc( $atts, $content = &#039;&#039; ) {\n\t\tglobal $ap_shortcode_loaded;\n\n\t\t\/\/ Drop current page variable cache. As we are allowing to change page from shortcode.\n\t\twp_cache_delete( &#039;current_page&#039;, &#039;anspress&#039; );\n\n\t\t\/\/ Check if AnsPress shortcode already loaded.\n\t\tif ( true === $ap_shortcode_loaded ) {\n\t\t\treturn __( &#039;AnsPress shortcode cannot be nested.&#039;, &#039;anspress-question-answer&#039; );\n\t\t}\n\n\t\twp_enqueue_script( &#039;anspress-main&#039; );\n\t\twp_enqueue_script( &#039;anspress-theme&#039; );\n\t\twp_enqueue_style( &#039;anspress-main&#039; );\n\t\twp_enqueue_style( &#039;anspress-fonts&#039; );\n\n\t\t$ap_shortcode_loaded = true;\n\n\t\t$this-&gt;attributes( $atts, $content );\n\n\t\tob_start();\n\t\techo &#039;&lt;div id=&quot;anspress&quot; class=&quot;anspress&quot;&gt;&#039;;\n\n\t\t\t\/**\n\t\t\t * Action is fired before loading AnsPress body.\n\t\t\t *\/\n\t\t\tdo_action( &#039;ap_before&#039; );\n\n\t\t\t\/\/ Include theme file.\n\t\t\tap_page( $this-&gt;current_page );\n\n\t\techo &#039;&lt;\/div&gt;&#039;;\n\t\t\/\/ Linkback to author.\n\t\tif ( ! ap_opt( &#039;author_credits&#039; ) ) {\n\t\t\techo &#039;&lt;div class=&quot;ap-cradit&quot;&gt;&#039; . esc_attr__( &#039;Question and answer is powered by&#039;, &#039;anspress-question-answer&#039; ) . &#039; &lt;a href=&quot;https:\/\/anspress.net&quot; target=&quot;_blank&quot;&gt;anspress.net&lt;\/a&gt;&lt;\/div&gt;&#039;;\n\t\t}\n\n\t\twp_reset_postdata();\n\t\t$ap_shortcode_loaded = false;\n\t\treturn ob_get_clean();\n\t}\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\">anspress-question-answer\/anspress-question-answer\/includes\/class-theme.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\">AnsPress [question] Shortcode<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The AnsPress Question Shortcode is designed to display a specific question on a webpage. It fetches the question using the provided ID within the shortcode.\n\n \n\nThe shortcode starts by setting up a buffer and creating a div for the question. It then checks if the ID provided is valid and fetches the corresponding question. If the question exists, it is displayed using the question template. If not, an error message is shown. After displaying the question or error message, the post data is reset and the buffered content is returned.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode<\/strong>: <code>[question]<\/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 question shortcode parameters and attributes:<\/p>\n\n\n<ul>\n<li><code>ID<\/code> &#8211; The unique identifier for the question.<\/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; The shortcode displays a specific question from the AnsPress Question Answer plugin using the question&#8217;s ID.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[question id=1 \/]<\/code><\/pre>\n\n\n<p><strong>Advanced examples<\/strong><\/p>\n<p>Using the shortcode to display a specific question by referencing the ID. If the question with the given ID does not exist, an error message will be displayed.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[question ID=5 \/]<\/code><\/pre>\n\n\n<p>It&#8217;s also possible to use lowercase &#8216;id&#8217; in the shortcode. The functionality remains the same, it will display the question with the specified id or an error message if the question does not exist.<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[question id=5 \/]<\/code><\/pre>\n\n\n<p>Please note that the &#8216;id&#8217; in the shortcode refers to the ID of the question in the AnsPress Question Answer plugin, not the post ID of the page or post where the shortcode is used.<\/p>\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>[question]<\/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( 'question', array( AnsPress_Question_Shortcode::get_instance(), 'anspress_question_sc' ) );<\/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 anspress_question_sc( $atts, $content = &#039;&#039; ) {\n\t\tob_start();\n\t\techo &#039;&lt;div id=&quot;anspress&quot; class=&quot;ap-eq&quot;&gt;&#039;;\n\n\t\t\/**\n\t\t * Action is fired before loading AnsPress body.\n\t\t *\/\n\t\tdo_action( &#039;ap_before_question_shortcode&#039; );\n\n\t\t$id = ! empty( $atts&#91;&#039;ID&#039;] ) ? absint( $atts&#91;&#039;ID&#039;] ) : absint( $atts&#91;&#039;id&#039;] );\n\n\t\t$questions = ap_get_question( $id );\n\n\t\tif ( $questions-&gt;have_posts() ) {\n\t\t\t\/**\n\t\t\t * Set current question as global post\n\t\t\t *\n\t\t\t * @since 2.3.3\n\t\t\t *\/\n\n\t\t\twhile ( $questions-&gt;have_posts() ) :\n\t\t\t\t$questions-&gt;the_post();\n\t\t\t\tinclude ap_get_theme_location( &#039;shortcode\/question.php&#039; );\n\t\t\tendwhile;\n\t\t} else {\n\t\t\tesc_attr_e( &#039;Invalid or non existing question id.&#039;, &#039;anspress-question-answer&#039; );\n\t\t}\n\n\t\techo &#039;&lt;\/div&gt;&#039;;\n\t\twp_reset_postdata();\n\n\t\treturn ob_get_clean();\n\t}\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\">anspress-question-answer\/anspress-question-answer\/includes\/class-theme.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>AnsPress \u2013 Question and answer Plugin shortcodes<\/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 AnsPress \u2013 Question and answer Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we&#8217;ll assist you with common issues that might cause the AnsPress \u2013 Question and answer Plugin shortcodes 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":"AnsPress &#8211; Question and answer","slug":"","version":"4.3.2","author":"<a href=\"https:\/\/anspress.net\">Rahul Aryan<\/a>","icons":"https:\/\/ps.w.org\/anspress-question-answer\/assets\/icon-128x128.png?rev=2432843","plugin_tags":"{\"answer\":\"answer\",\"forum\":\"forum\",\"profile\":\"profile\",\"qa\":\"q&amp;a\",\"question\":\"question\"}","author_profile":"https:\/\/profiles.wordpress.org\/lattepress\/","requires":"4.7","tested":"6.2.3","requires_php":"false","rating":80,"num_ratings":98,"active_installs":4000,"downloaded":235048,"last_updated":"2023-07-15 5:04am GMT","added":"2014-10-20","homepage":"https:\/\/anspress.net","short_description":"A free question and answer plugin for WordPress. Made with developers in mind, and highly customizable.","description":"\"AnsPress - Question and Answer is a dynamic WordPress plugin perfect for creating interactive Q&A forums on your site. With this, engage your audience in thoughtful discussions.\"","shortcodes":"[\"apcode\",\"anspress\",\"question\"]","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1819","post","type-post","status-publish","format-standard","hentry","category-plugins"],"_links":{"self":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/1819","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=1819"}],"version-history":[{"count":1,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/1819\/revisions"}],"predecessor-version":[{"id":2381,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/1819\/revisions\/2381"}],"wp:attachment":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/media?parent=1819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/categories?post=1819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/tags?post=1819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}