• Resolved oberajter

    (@oberajter)


    <?php previous_post_link( ‘%link’,'<img src=”wp-content/themes/snaps/images/bal.png” width=”200px” height=”196px”/>’); ?>

    the code above is from my PHP template. It is used for linking between the posts, but it’s not working properly. The image appears as a broken image, but the link is working. What could be the problem?
    When I try to put it for example on the Home page and the image appears.

Viewing 2 replies - 1 through 2 (of 2 total)
  • It’s because you’re using a relative URL, which is relative to the current page. On the home page it works because the relative URL starts from the correct place, but on a single post view, the URL to the image ends up being something like yourdomain.com/wordpress/2016/06/11/foo/wp-content/themes/snaps/images/bal.png (depending on your permalink settings), which obviously isn’t correct. You could try using text replacement:

    <?php previous_post_link( '%link',sprintf( '<img src="%s" width="200px" height="196px"/>', get_template_directory_uri() . '/images/bal.png' ) ); ?>

    This way the correct absolute path gets passed in automatically.

    Thread Starter oberajter

    (@oberajter)

    Thank you. It works now.:)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Next And Previous Links On WordPress Posts’ is closed to new replies.