{"id":41,"date":"2025-09-26T08:50:52","date_gmt":"2025-09-26T08:50:52","guid":{"rendered":"https:\/\/ska-blocks.com\/docs\/2025\/09\/26\/dynamic-links\/"},"modified":"2025-09-26T09:36:13","modified_gmt":"2025-09-26T09:36:13","slug":"dynamic-links","status":"publish","type":"post","link":"https:\/\/ska-blocks.com\/docs\/dynamic-links\/","title":{"rendered":"Dynamic links"},"content":{"rendered":"\n<p>The dynamic links interface will appear on the block toolbar when using <a href=\"https:\/\/ska-blocks.com\/docs\/ska-blocks\/element-block\/\" data-type=\"post\" data-id=\"203\">Element<\/a> or <a href=\"https:\/\/ska-blocks.com\/docs\/ska-blocks\/text-block\/\" data-type=\"post\" data-id=\"213\">Text<\/a> blocks with the HTML tag name <code>&lt;a&gt;<\/code>:<\/p>\n\n\n\n<div role=\"figure\" class=\"wp-block-ska-image image\"><img decoding=\"async\" src=\"https:\/\/ska-blocks.com\/docs\/wp-content\/uploads\/sites\/3\/2024\/02\/image-1.png\" width=\"409\" height=\"272\" loading=\"lazy\"\/><\/div>\n\n\n\n<p class=\"text-sm\">Not to be confused with another &#8220;link&#8221; item on the toolbar that is used for adding a link to Rich Text (as in it will not add a link to the block&#8217;s root element, but will wrap some part of the text inside the block in an additional <code>&lt;a&gt;<\/code> element which is not valid HTML):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/ska-blocks.com\/docs\/wp-content\/uploads\/sites\/3\/2024\/03\/image-73.png\" alt=\"\" class=\"wp-image-419\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Some of the Dynamic links (E-mail, Phone, Facebook, Instagram) on the above example picture are static links from the <a href=\"https:\/\/ska-blocks.com\/docs\/ska-blocks\/dynamic-content\/\" data-type=\"post\" data-id=\"417\">Dynamic content<\/a> option. The Front page, Blog, Permalink and Privacy policy links, how ever are registered via <strong>Dynamic links API<\/strong>  provided by ska-blocks plugin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Add a dynamic link<\/h2>\n\n\n\n<p>Additional dynamic links can be registered with the following code:<\/p>\n\n\n\n<div class=\"wp-block-ska-code not-prose ska-preset--ska-theme--code\"><header><span class=\"title\">Custom dynamic link<\/span><span class=\"label language-php\">PHP<\/span><\/header><div class=\"content\"><pre class=\"code php language-php\"><code class=\"language-php\">add_action('ska_blocks_init', function() {\n\n\tska_blocks()->get('dynamic-links')->register_dynamic_link(&#91;\n\t\t'slug' => 'link-slug',\n\t\t'label' => 'Link title',\n\t\t'callback' => function($link_attrs, $block) {\n\t\t\treturn 'https:\/\/example.com';\n\t\t},\n\t\t'is_active' => function($link_attrs, $block) {\n\t\t\treturn false;\n\t\t},\n\t]);\n});<\/code><\/pre><button :class=\"{error: state === &apos;error&apos;, success: state === &apos;success&apos;}\" x-data=\"{state:&apos;&apos;}\" x-on:click=\"navigator.clipboard ? (navigator.clipboard.writeText($el.previousElementSibling.innerText), $el.innerText = `Copied!`, state = &apos;success&apos;) : ($el.innerText = `Can&amp;#039;t copy`, state = &apos;error&apos;)\" class=\"copy\" type=\"button\">Copy<\/button><\/div><\/div>\n\n\n\n<p>You should provide a <strong>slug<\/strong>, <strong>label<\/strong> and a <strong>callback<\/strong> to the <code>register_dynamic_link<\/code> function. <strong>is_active<\/strong> function is optional.<\/p>\n\n\n\n<p>The arguments for the callback functions are as follows:<\/p>\n\n\n\n<div class=\"wp-block-ska-code not-prose ska-preset--ska-theme--code\"><div class=\"content\"><pre class=\"code php language-php\"><code class=\"language-php\">\/**\n * @param array $link_attrs Array containing link attributes.\n * @param WP_Block $block Block instance.\n *\/<\/code><\/pre><\/div><\/div>\n\n\n\n<p>Once added your dynamic link should show up under Dynamic links when editing a link of Element or Text blocks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The dynamic links interface will appear on the block toolbar when using Element or Text blocks with the HTML tag name &lt;a&gt;: Not to be confused with another &#8220;link&#8221; item on the toolbar that is used for adding a link to Rich Text (as in it will not add a link to the block&#8217;s root&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-ska-blocks"],"_links":{"self":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":1,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":198,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/41\/revisions\/198"}],"wp:attachment":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}