WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I want to do is output a custom field content (which is a button with a dynamic link that's being inserted in the value of the custom field of each posts) right after the_content and before the plugins.

This is the code for the custom field:

<div class="button">
  <a href="<?php echo get_post_meta($post->ID, 'Button', true); ?>">
    <img src="<?php echo get_template_directory_uri() . '/images/button.png'; ?>" alt="link" />

On wordpress codex I also found this example of how to apply a filter to the_content in order to obtain something similar to what I want. This is the code:

add_filter( 'the_content', 'my_the_content_filter', 20 );

* Add a icon to the beginning of every post page.
* @uses is_single()
function my_the_content_filter( $content ) {
if ( is_single() )
    // Add image to the beginning of each page
    $content = sprintf(
        '<img class="post-icon" src="%s/images/post_icon.png" alt="Post icon" title=""/>%s',
        get_bloginfo( 'stylesheet_directory' ),

// Returns the content.
return $content;

The problem is I don't know PHP and I have no idea how am I supposed to edit the above code to apply on my specific case.

share|improve this question
up vote 0 down vote accepted

This is the answer - code to be added in the functions.php:

add_filter( 'the_content', 'my_the_content_filter', 0 );
function my_the_content_filter( $content ) {
if ( is_single() )
    global $post;
    $pgLnk=get_post_meta($post->ID, 'Button', true);
    $content .= '<div id="button-link"><a href="'.$pgLnk.'" target="_blank">
    <span class="button-link"></span></a></div>';
return $content;

This code was wrote by @Sheikh Heera on stackoverflow.com - direct link

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.