{"id":913,"date":"2020-07-14T11:59:23","date_gmt":"2020-07-14T15:59:23","guid":{"rendered":"http:\/\/tech.creed3.com\/?p=913"},"modified":"2020-07-14T11:59:23","modified_gmt":"2020-07-14T15:59:23","slug":"re-purpose-the-wordpress-links-blogroll-as-a-link-page-or-directory-without-a-plugin","status":"publish","type":"post","link":"https:\/\/tech.creed3.com\/?p=913","title":{"rendered":"Re-purpose The WordPress Links (Blogroll) as a Link Page or Directory Without a Plugin"},"content":{"rendered":"<p><img decoding=\"async\" style=\"margin: 0 4px 4px 0;\" alt=\"\" src=\"images\/stories\/wordpress-logo-simplified-rgb.png\" width=\"100\" align=\"left\" border=\"0\" \/>WordPress has a built-in links manager. &nbsp;It was basically intended to be used for what was and still is referred to as a blogroll. &nbsp;Blogrolls aren&#8217;t quite as popular today but don&#8217;t let this feature go to waste. &nbsp;If you have been thinking about adding a page of links you want to direct your users to, or feature a small links directory, here&#8217;s how to do it without adding a plugin.<!--more--><\/p>\n<p>In a new install of WordPress you might not see the links manager in the admin page menu because starting with version 3.5 WordPress disabled this feature. &nbsp;There are many other sites out there with instructions on how to enable it but I&#8217;ll save you the searching and add that here.<\/p>\n<p>To do what we want to do you need to be comfortable with editing your theme functions.php file. &nbsp;If you aren&#8217;t, to quote a scene from Monty Python&#8217;s Holy Grail, &#8220;Run away! Run away!&#8221;.<\/p>\n<p><strong>Enable The Links Manger<\/strong><br \/>\nAdd the following to your WordPress functions.php file:<\/p>\n<pre><code>add_filter( 'pre_option_link_manager_enabled', '__return_true' );<\/code><\/pre>\n<p>Done!<\/p>\n<p><strong>Set Up A Links Page<\/strong><br \/>\nStill editing your theme functions.php file, we will now add a new function that will create a shortcode to generate a links page using the links you have in your links manager. &nbsp;Add this to the functions.php file:<\/p>\n<pre><code style=\"font-size:12px;\">\/\/ Shortcode :: Display Links \/\/\r\nfunction c3showlinks_shortcode($atts) {\r\n  &nbsp; echo '&lt;ul class=\"links\"&gt;';\r\n  &nbsp; echo wp_list_bookmarks('categorize=1&amp;hide_invisible=1&amp;show_description=1');\r\n  &nbsp; echo '&lt;\/ul&gt;';\r\n}\r\nadd_shortcode('c3showlinks', 'c3showlinks_shortcode');<\/code><\/pre>\n<p>The shortcode we&#8217;re creating here is called &#8220;c3showlinks&#8221;. &nbsp;You can of course name this what ever you would like as long as you follow through with the new name.<\/p>\n<p>Next, create a new page on your WordPress site. &nbsp;Let&#8217;s just title it &#8220;Links&#8221; and in the page content window simply place nothing but this shortcode:<\/p>\n<pre><code>[c3showlinks]<\/code><\/pre>\n<p>Now save your new Links page and take a look. &nbsp;Of course you&#8217;ll want to add some categories and links in the link manager. &nbsp;You&#8217;ll probably want to add some CSS styling as well. &nbsp;The new shortcode function assigns the class &#8220;links&#8221; to the result. &nbsp;So in your stylesheet you could add something like this:<\/p>\n<pre><code>.postentry ul.links {\r\n\tlist-style-type: none;\r\n\tmargin-left: 0;\r\n\tpadding-left: 20px;\r\n}<\/code><\/pre>\n<p>The above style sets the margin, padding, and removes the marker before each category name. &nbsp;Additional styling helps refine further the font size and weight for the category name using<\/p>\n<pre><code>.linkcat h2 {}<\/code><\/pre>\n<p>To set the style for the links use<\/p>\n<pre><code>.blogroll li {}<\/code><\/pre>\n<p>In both instances above the class is automatically set by WordPress.<\/p>\n<p>There are many options you can call in the wp_list_bookmarks() function to further stylize your list of links. &nbsp;Refer to the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_list_bookmarks\/\" rel=\"noopener noreferrer\" target=\"_blank\">WordPress function reference<\/a> for more info on that.<\/p>\n<p>And there you have it. &nbsp;Simple and no additional plugins required. &nbsp;Hopefully this has given you some ideas on expanding your WordPress site with some built-in and little used functionality.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress has a built-in links manager. &nbsp;It was basically intended to be used for what was and still is referred to as a blogroll. &nbsp;Blogrolls aren&#8217;t quite as popular today but don&#8217;t let this feature go to waste. &nbsp;If you have been thinking about adding a page of links you want to direct your users [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,30,41],"tags":[83,84,31],"class_list":["post-913","post","type-post","status-publish","format-standard","hentry","category-technology","category-web-development","category-wordpress","tag-link-manager","tag-links-page","tag-wordpress"],"views":1554,"_links":{"self":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/posts\/913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=913"}],"version-history":[{"count":0,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/posts\/913\/revisions"}],"wp:attachment":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}