Support » Plugin: Simple Links » Add and display custom fields like %class%, %itemprop%

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mat Lipe

    (@mat-lipe)

    Hi iox,

    Are you trying to used the custom fields as link attributes such as ‘class=”mail-link”‘? Or are you trying to display the custom fields below the links?

    link attributes

    Yes!

    Plugin Author Mat Lipe

    (@mat-lipe)

    Hi iox,

    Currently there is no way to do this through the admin, however it is on the list for possibilities when version 2.0 is released.

    You may accomplish this adding the following code to your themes functions.php file.

    add_filter('simple_links_shortcode_link_output', 'add_simple_link_attribute', 1, 4 );
    add_filter('simple_links_widget_link_output', 'add_simple_link_attribute', 1, 4);
    function add_simple_link_attribute($output, $meta, $link, $image){
        $atts = ' ';
        foreach( (array)json_decode($meta['link_additional_value'][0]) as $k => $v){
            $atts .= sanitize_title($k).'="'.sanitize_text_field($v).'" ';
    
        }
    
        $output = sprintf('<a href="%s" target="%s" title="%s" %s%s>%s%s</a>',
                        $meta['web_address'][0],
                        $meta['target'][0],
                        strip_tags($meta['description'][0]),
                        $atts,
                        empty( $meta['link_target_nofollow'][0] ) ? '': 'rel="nofollow"',
                        $image,
                        $link->post_title
                );
        return $output;
    }

    This will adjusted both the widget and the shortcode. All additional fields will be added to the links as attributes.

    Hope this helps.

    I think it would be a good option for semantics and microdata.
    Like…

    <a href="mailto:#"
        class="email"
        itemprop="email"
    >mail</a>
    <a href="tel:911"
        class="telephone"
        itemprop="telephone"
    >911</a>

    Thanks, Mat!

    resolved

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add and display custom fields like %class%, %itemprop%’ is closed to new replies.