2 comments

  1. There are a couple of problems with your code:

    1. You have to close the PHP context, if you want to output plain HTML: function foo(){ ?><strong><?php }
    2. Don’t repeat yourself. Always store repeating values in variables or functions. Writing <a href more than once is a bug.
    3. Do not use get_the_title() in attributes. Use the_title_attribute( array ( 'echo' => FALSE ) ) instead, or you can get unexpected markup into your HTML output.
    4. Do not use bloginfo('stylesheet_directory'). Use get_stylesheet_directory_uri() in child themes only and get_template_directory_uri() in all other cases.
    5. Do not double-escape the &.
    6. The share URL for Delicious is https://delicious.com/post?. It has been that for years.

    The resulting code could look like this:

    function pietergoosen_sosiale_netwerk_deel_knoppies()
    {
        $services = array (
            'facebook' => array (
                'url'  => 'http://www.facebook.com/sharer.php?u=%1$s&amp;t=%2$s',
                'text' => 'Share on Facebook.'
            ),
            'twitter' => array (
                'url'  => 'http://twitter.com/home/?status=%1$s%%20-%%20%2$s',
                'text' => 'Tweet this!'
            ),
            'google' => array (
                'url'  => 'http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=%2$s&amp;t=%2$s',
                'text' => 'Google+1.'
            ),
            'stumbleupon' => array (
                'url'  => 'http://www.stumbleupon.com/submit?url=%1$s&amp;title=%2$s',
                'text' => 'StumbleUpon.'
            ),
            'digg' => array (
                'url'  => 'http://digg.com/submit?phase=2&amp;url=%1$s&amp;title=%2$s',
                'text' => 'Digg this!'
            ),
            'delicious' => array (
                'url'  => 'https://delicious.com/post?url=%1$s&amp;title=%2$s',
                'text' => 'Bookmark on Delicious.'
            ),
            'gmail' => array (
                'url'  => 'https://mail.google.com/mail/?view=cm&amp;fs=1&amp;to&amp;su=%1$s&amp;t=%2$s',
                'text' => 'Share per Gmail.'
            )
        );
        $img_base = get_template_directory_uri() . '/images/%s.png';
        $title    = the_title_attribute( array ( 'echo' => FALSE ) );
        $url      = urlencode( get_permalink() );
    
        print '<h4>Deel die pos met ander</h4>';
    
        foreach ( $services as $name  => $service )
        {
            $href = sprintf( $service['url'], $url, urlencode( $title ) );
            $src  = sprintf( $img_base, $name );
    
            printf(
                '<a href="%1$s" title="%2$s"><img src="%3$s" alt="%2$s" /></a>',
                $href,
                esc_attr( $service['text'] ),
                $src
            );
        }
    }
    

    Now you can call this function in a template:

    pietergoosen_sosiale_netwerk_deel_knoppies();
    
  2. First of all, you never closed your php tags.

    Second of all, do not call functions each time for each social icon. Save values in the variables instead to speed up the process.

    It would go something like this:

    <?php function my_social_buttons() {
    
        $title = esc_attr( get_the_title() );
        $permalink = esc_attr( get_the_permalink() );
        $directory = get_template_directory_uri();
    
        ?>
        <strong>Deel die pos met ander</strong>
        <a href="http://www.facebook.com/sharer.php?u=<?php echo $permalink;?>&amp;amp;t=<?php echo $title; ?>" title="Share on Facebook.">
        <img src="<?php echo $directory; ?>/images/facebook.png" alt="Share on Facebook" id="sharethis-last" /></a>
        <a href="http://twitter.com/home/?status=<?php echo $title; ?> : <?php echo $permalink; ?>" title="Tweet this!">
        <img src="<?php echo $directory; ?>/images/twitter.png" alt="Tweet this!" /></a>
        <a href="http://www.google.com/bookmarks/mark?op=edit&bkmk=<?php echo $permalink;?>&amp;amp;t=<?php echo $title; ?>" title="Google+1.">
        <img src="<?php echo $directory; ?>/images/google.png" alt="Google+1" id="Google+1" /></a>
        <a href="http://www.stumbleupon.com/submit?url=<?php echo $permalink; ?>&amp;amp;title=<?php echo $title; ?>" title="StumbleUpon.">
        <img src="<?php echo $directory; ?>/images/stumbleupon.png" alt="StumbleUpon" /></a>
        <a href="http://digg.com/submit?phase=2&amp;amp;url=<?php echo $permalink; ?>&amp;amp;title=<?php echo $title; ?>" title="Digg this!">
        <img src="<?php echo $directory; ?>/images/digg.png" alt="Digg This!" /></a>               
        <a href="http://del.icio.us/post?url=<?php echo $permalink; ?>&amp;amp;title=<?php echo $title; ?>" title="Bookmark on Delicious.">
        <img src="<?php echo $directory; ?>/images/delicious.png" alt="Boekmerk op Delicious" /></a>
        <a href="https://mail.google.com/mail/?view=cm&fs=1&to&su=<?php echo $permalink;?>&amp;amp;t=<?php echo $title; ?>" title="epos.">
        <img src="<?php echo $directory; ?>/images/gmail.png" alt="epos" id="epos dit" /></a> 
    
        <?php
    
    }
    

Comments are closed.