function tags() {
$tags = get_field_object('метки_и_ссылки', get_queried_object());
echo "<div class='theme-container tag-container'><ul class='tag-links'>";
foreach( $tags['value'] as $tag['value'] ) {
echo "<a class='tag-link' href='";
echo $tag['value'] -> description;
echo "'>";
echo $tag['value'] -> name;
echo "</a>";
}
echo "</ul></div>";
}
add_shortcode('tagsAndLinks', 'tags');
Note that the function called by the shortcode should never produce an output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results. This is similar to the way filter functions should behave, in that they should not produce unexpected side effects from the call since you cannot control when and where they are called from.
<ul>
можно вкладывать только элементы <li>
// Использование [tag-list field="метки_и_ссылки" class="tag-list"]
add_shortcode( 'tag-list', 'get_custom_tag_list' );
function get_custom_tag_list( $atts ) {
// белый список параметров и значения по умолчанию для шорткода
$atts = shortcode_atts( array(
'class' => 'list',
'field' => '',
'post_id' => 0
), $atts );
$output = '';
$post = get_post( $atts['post_id'] );
if ( isset( $post->ID ) && !empty($atts['field']) ) {
$tags = get_field_object( $atts['field'], $post->ID );
if ( $tags ) {
$output .= '<ul class="' . $atts['class'] . '">';
foreach ( $tags['value'] as $key => $value ) {
$output .= '<li class="' . $atts['class'] . '__item" >';
$output .= '<a class="' . $atts['class'] . '__link" href="' . $value->description . '" rel="tag">' . $value->name . '</a>';
$output .= '</li>';
}
$output .= '</ul>';
}
}
return apply_filters( 'get_custom_tag_list', $output );
}