WordPress.org

Ready to get started?Download WordPress

Forums

Simple Links
[resolved] Add and display custom fields like %class%, %itemprop% (6 posts)

  1. iox
    Member
    Posted 12 months ago #

    Hi, Mat.

    The plugin is very good, as it allows you to add custom fields. But I don't understand how to generate links with custom fields (-_-). If possible, please write a simple example...

    <a href="#" class="mail-link">E-Mail</a>

    Thanks for help.

    http://wordpress.org/extend/plugins/simple-links/

  2. Mat Lipe
    Member
    Plugin Author

    Posted 12 months ago #

    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?

  3. iox
    Member
    Posted 12 months ago #

    link attributes

    Yes!

  4. Mat Lipe
    Member
    Plugin Author

    Posted 12 months ago #

    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.

  5. iox
    Member
    Posted 12 months ago #

    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!

  6. iox
    Member
    Posted 12 months ago #

    resolved

Reply

You must log in to post.

About this Plugin

About this Topic