0

i add content automatically content with this code on each posts on my wordpress:

function insertFootNote($content){        
          if(!is_feed() && !is_home()) {               
                              $content.= "<div class='FollowMe'>";                
                              $content.= "<h4>Enjoyed this article?</h4>";                
                              $content.= "<p>Follow me .</p>";               
                              $content.= "</div>";}        
         return $content;}
         add_filter ('the_content', 'insertFootNote');

This works fine but now when i try to insert some images:

$content.= "<p> style="text-align: center;"><a href="http://www.especie.info/submit/"><img class="alignnone size-medium wp-image-744" src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-236x300.png" alt="imgpsh_fullsize" width="236" height="300" /></a> <a href="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2.png"><img class="alignnone size-medium wp-image-743" src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2-236x300.png" alt="imgpsh_fullsize-2" width="236" height="300" /></a></p>";  

I get this error: Parse error: syntax error, unexpected 'text' (T_STRING).

Thanks for all your help.

1 Answers1

0

This is because you have double qoutes nested inside double quotes, cancelling themselves out.

The following code that you submitted refactored:

$content .= "
        <p> style="text-align: center;">
            <a href="http://www.especie.info/submit/">
                <img class="alignnone size-medium wp-image-744" 
                src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-236x300.png" alt="imgpsh_fullsize" width="236" height="300" />
            </a> 
            <a href="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2.png">
                <img class="alignnone size-medium wp-image-743" 
                src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2-236x300.png" alt="imgpsh_fullsize-2" width="236" height="300" />
            </a></p>";

Should become:

$content = '
        <p style="text-align: center;">
            <a href="http://www.especie.info/submit/">
                <img class="alignnone size-medium wp-image-744" 
                src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-236x300.png" alt="imgpsh_fullsize" width="236" height="300" />
            </a> 
            <a href="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2.png">
                <img class="alignnone size-medium wp-image-743" 
                src="http://www.especie.info/wp-content/uploads/2015/09/imgpsh_fullsize-2-236x300.png" alt="imgpsh_fullsize-2" width="236" height="300" />
            </a>
        </p> ';

Side Note

You also didn't encapsulate the style tag into the first paragraph tag. This has been corrected in the refactored version. Hope this helps!

ham-sandwich
  • 3,975
  • 10
  • 34
  • 46