I spent about 2 hours trying to make a blending of 2 codes work, and feeling the weakness of my code skills, I am reaching out here for some help.
I think the problem lies in the single/double quotes. I tried many, many times to reformat the quotations (and both ways ie reformatting both scripts to accommodate each other).
The image (which should be linked) is added to the page in the functions.php -- the image is path/image.png in this example:
! is_admin() && add_filter( 'the_content', function( $content )
{
if( in_the_loop() ) // <-- Target the main loop
{
$prepend = "<div style='color:#808080 ; border:1px solid #909090 ; border-radius:5px; float:left; padding-top:1px;'> <**img src='/path/image.png' alt='Tweet this' style='margin-bottom: -4px; '**>Tweet this  </div> ";
$content = $prepend . $content;
}
return $content;
}, 9 );
This is the link -- When the user clicks the image, I want them to access this link:
<a href='https://twitter.com/share?url=<?php echo $post_url ?>&text=<?php echo $post_title ?>' onclick='window.open(this.href,"popupwindow", "width=800,height=500,left=200,top=5,scrollbars,toolbar=0,resizable"); return false;' Target='_blank' >twitter</a>
What I want to end up with is: Click the image on the page, (it opens the Twitter link,) user gets to Tweet (share) the post they are on on Twitter.
So user clicks image (path/image.png) and opens link (twitter.com...etc).
Still not sure of anything: you should realize that your question lacks clarity.
Notably because you don't say where
$post_url
and$post_title
comes from, nor explain what are$prepend
and$content
, and don't explain at all your function's use and context.But I'll talk about what I believe to have understood.
Your goal seems to result in this kind of HTML part:
(you'll notice that I've returned back to arbitrary give precedence to double-quotes, which is the most standard choice)
Say we call
$div
,$a
, and$img
the source main components, to output the desired block we simply have to write something like:echo $div . $a . $img . 'Tweet this  </a></div';
I suppose the issue you're reporting comes from you have to define those components as strings, while they already include simple and double quotes.
So the answer is using the PHP heredoc syntax:
And the components definition should look like:
In fact many other variations may be considered, notably directly using a unique variable for the whole part...
EDIT:
Here is a working whole snippet, after integrating a value for
$post_url
and$post_title
and corrected a typo inecho...
: