Skip to content

Commit

Permalink
Use post_name instead of permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwoodnz committed Oct 3, 2024
1 parent 05ff02f commit 286a4e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mu-plugins/blocks/link-wrapper/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ function init() {
* @param string $content Block content.
* @return string Rendered block HTML.
*/
function render( $attributes, $content ) {
function render( $attributes, $content, $block ) {
$post_id = $block->context['postId'];
$post_slug = get_post_field( 'post_name', $post_id );
$link = isset( $attributes['url'] ) ? ' ' . $attributes['url'] : site_url( $post_slug );

$wrapper_attributes = get_block_wrapper_attributes();
$link = isset( $attributes['url'] ) ? ' ' . $attributes['url'] : get_permalink();

return sprintf(
'<a href="%1$s" %2$s>%3$s</a>',
Expand Down
1 change: 1 addition & 0 deletions mu-plugins/blocks/link-wrapper/src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"icon": "admin-links",
"category": "layout",
"description": "Link a set of blocks to a given page.",
"usesContext": [ "postId" ],
"textdomain": "wporg",
"attributes": {
"url": {
Expand Down

0 comments on commit 286a4e3

Please sign in to comment.