[ad_1]
Replies: 1
Hi i’m beginer
first i made follow this content https://goldpenguin.org/blog/create-custom-tag-and-category-buttons-for-blogs-in-breakdance/ Updated September 10, 2023
<?php
function gpbd_tag_wrap_shortcode( $atts ) {
global $post;
$tags = get_the_tags( $post->ID );
if ( !empty( $tags ) ) {
$output="<div class="post-tags">";
foreach ( $tags as $tag ) {
$output .= '<a href="' . esc_url( get_tag_link( $tag->term_id ) ) . '">#' . esc_html( $tag->name ) . '</a> ';
}
$output = rtrim( $output, ' ' ); // Remove the last comma
$output .= '</div>';
return $output;
}
}
add_shortcode( 'tagwrap', 'gpbd_tag_wrap_shortcode' ); // Usage: #Blog Design #Breakdance Builder #UI/UX #Website Development #WordPress
// Add CSS styles to the header
function gpbd_tag_wrap_styles() {
?>
<style>
.post-tags {
display: block;
margin: 10px 0;
font-size: 16px;
}
.post-tags a {
display: inline-block;
padding: 3px 6px;
margin-right: 4px;
background-color: #f2f2f2;
color: #333;
text-decoration: none;
border-radius: 5px;
}
.post-tags a:hover {
background-color: #333;
color: #fff;
}
</style>
<?php
}
add_action( 'wp_head', 'gpbd_tag_wrap_styles' ); // Add CSS to the header of the website
?>
i have error in my website Full Error message: Attempt to read property “ID” on null
2024-07-31T19:49:43+00:00 Snippet “Custom Post Tags” (#64) was automatically deactivated due to a fatal error. 2024-07-31T19:49:44+00:00 Attempt to read property “ID” on null
How i can fixit
Regards,
Tanapat