• Hi,

    this code works:
    <?php next_posts_link('<img src="https://www.joelcormack.com/mxmg.com/wordpress/wp-content/themes/marinelogix-light-and-dark/images/next.png" />'); ?>

    this code doesn’t:
    <?php previous_posts_link('<img src="<?php bloginfo('template_directory'); ?>/images/previous.png" />'); ?>

    I’ve searched these forums but can’t seem to find a way of properly pulling images from within the next and previous posts links. Is there a way it can be done, without hard coding?

    My text editor doesn’t like like the latter code either and says its a parse error.

    any help would be most appreciated.

Viewing 1 replies (of 1 total)
  • You are including an opening and closing set of <?php ?> tags, within an already open set of <?php ?> tags. This is confusing the PHP interpreter and causing it to choke.

    What you are essentially trying to do is concatenate a string (the <img> string), for use with the previous_posts_link() function.

    So this :
    ‘<img src=”<?php bloginfo(‘template_directory’); ?>/images/previous.png” />’

    Should be something more like this :
    '<img src="' . get_template_directory_uri() . '/images/previous.png" />'

    Which would make your full previous_posts_link code look more like this :
    <?php previous_posts_link('<img src="' . get_template_directory_uri() . '/images/previous.png" />'); ?>

    Or, if you prefer to be more verbose, for clarity, declare the string as a variable separately, and pass that variable into the function, like this :

    <?php
    $label = '<img src="' . get_template_directory_uri() . '/images/previous.png" />';
    previous_posts_link($label);
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Parse error using previous_posts_link()’ is closed to new replies.