{"id":2536,"date":"2012-10-05T11:37:41","date_gmt":"2012-10-05T18:37:41","guid":{"rendered":"http:\/\/www.eaf.net\/mvp\/?p=2536"},"modified":"2012-10-05T11:37:41","modified_gmt":"2012-10-05T18:37:41","slug":"my-first-wordpress-shortcode","status":"publish","type":"post","link":"https:\/\/www.eaf.net\/mvp\/2012\/my-first-wordpress-shortcode\/","title":{"rendered":"My First WordPress Shortcode"},"content":{"rendered":"<p>Up until early this morning, I&#8217;ve resisted using shortcodes in my WordPress blogs.<\/p>\n<p>But this morning I built my very own first custom shortcode. Sure, it&#8217;s simple and short and probably painfully plain. So?<\/p>\n<p>I plunked it in my active theme&#8217;s <i>functions.php<\/i> file and it works great! I know that by putting it there I&#8217;m limiting its application to my current theme. If I change themes, I&#8217;ll have to add the code to <i>that<\/i> theme&#8217;s <i>functions.php<\/i>. <!--more--><\/p>\n<p>That means that my shortcode is a prime textbook candidate for inclusion in a <a href=\"http:\/\/www.wpbeginner.com\/beginners-guide\/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin\/\" title=\"custom functions plugin\">custom functions plugin<\/a> instead. Then it would work from theme to theme. Maybe later I&#8217;ll do that.<\/p>\n<p>But never mind all that. I made my <a href=\"http:\/\/codex.wordpress.org\/Shortcode_API\" title=\"Shortcode API | WordPress Codex\">shortcode<\/a> by putting these four lines of code in my <a href=\"http:\/\/codex.wordpress.org\/Functions_File_Explained\" title=\"Functions File Explained | WordPress Codex\">functions.php<\/a> file:<\/p>\n<pre class=\"brush: php; title:  ; notranslate\" title=\" \">\r\nfunction dlink(){\r\n\treturn '&lt;a href=&quot;http:\/\/www.amazon.com\/gp\/product\/158134435X?ie=UTF8&amp;tag=anabaptistbookst&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=158134435X&quot;&gt;Daily Light on the Daily Path&lt;\/a&gt;&lt;img src=&quot;http:\/\/www.assoc-amazon.com\/e\/ir?t=anabaptistbookst&amp;l=as2&amp;o=1&amp;a=158134435X&quot; width=&quot;1&quot; height=&quot;1&quot; border=&quot;0&quot; alt=&quot;&quot; style=&quot;border:none !important; margin:0px !important;&quot; \/&gt;';\r\n}\r\nadd_shortcode('DLlink', 'dlink');\r\n<\/pre>\n<p>All I had to do to include it in my post was this: <code>[DLlink]<\/code>.<\/p>\n<p>Doing that generates a link to <i>Daily Light on the Daily Path<\/i> that is embedded with my Amazon affiliate stuff, like this: <a href=\"http:\/\/www.amazon.com\/gp\/product\/158134435X?ie=UTF8&#038;tag=anabaptistbookst&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=158134435X\">Daily Light on the Daily Path<\/a><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.assoc-amazon.com\/e\/ir?t=anabaptistbookst&#038;l=as2&#038;o=1&#038;a=158134435X\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" \/>.<\/p>\n<p><b>Very slick!<\/b> And I don&#8217;t need to get all that affiliate code every time I want to link to that book. I just have to put <code>[DLlink]<\/code> wherever I want that link to appear.<\/p>\n<p>To see the results live&#8230;and for hope in the middle of trouble&#8230;go to <a href=\"http:\/\/www.eaf.net\/pantinghart\/2012\/the-day-of-trouble\/\" title=\"The Day of Trouble | Panting Hart\">The Day of Trouble<\/a>.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Up until early this morning, I&#8217;ve resisted using shortcodes in my WordPress blogs. But this morning I built my very own first custom shortcode. Sure, it&#8217;s simple and short and probably painfully plain. So? I plunked it in my active theme&#8217;s functions.php file and it works great! I know that by putting it there I&#8217;m &#8230; <a title=\"My First WordPress Shortcode\" class=\"read-more\" href=\"https:\/\/www.eaf.net\/mvp\/2012\/my-first-wordpress-shortcode\/\" aria-label=\"More on My First WordPress Shortcode\">Read more<\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[13],"tags":[993,969,716],"class_list":["post-2536","post","type-post","status-publish","format-standard","hentry","category-tech-stuff","tag-blogging","tag-code","tag-wordpress"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/prJUJ-EU","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/posts\/2536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/comments?post=2536"}],"version-history":[{"count":0,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/posts\/2536\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/media?parent=2536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/categories?post=2536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.eaf.net\/mvp\/wp-json\/wp\/v2\/tags?post=2536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}