How do I assign this filter to a variable? (Appending php & markup to the_content)

Congratulations on (nearly) solving your problem already 🙂

There are 2 comments below the post that attempt to say how to do it the right way

They are proposing to do it this way:

function weedub_affiliate_filter($content) {
    $string_to_add = '';
    if (is_single()) {
        $string_to_add = $string_to_add . 'the string you wanted to add';
    }
    $content = $content . $string_to_add;
    return $content;
}

add_filter( 'the_content', 'weedub_affiliate_filter');

The difference to your current solution is that in this case the filter only filters the content. It does this by appending the two strings $content (a global variable) and $string_to_add.

In your solution, it prints it to the screen and then prints something else. The solution above allows for other filters to filter the content as well before printing it to the screen (which your current version does not, which is why some of your filters are broken).

// edit:
syntax error, unexpected T_STRING means that something concerning the single or double quotes is not right.

As you ar mixing php and html simply escaping the single quotes (as I mentioned earlier) will not be enough.

this code should (hopefully) work for you:

http://www.pastie.org/private/kzni3uxip0ze57krvtfyjg
(cannot get it to format right in this post…)

Leave a Comment