PHP to replace wordpress text - only nerds need apply

Status
Not open for further replies.

emp

New member
Jun 29, 2006
7,465
211
0
Arrrgh....I am officially too stupid to do this.

So I want to add some tracking to a WP LP.

To do so, I need to be able to replace a link to a redirect page with another one, based on the referer query.

Something along those lines:

Code:
$myRedirect = "redirect.php?q=".$query;
substr_replace ("redirect.php", $myRedirect, $postcontent);

But wordpress only has <?php the_content ?>

Where can I access the text?

ARGH...:anon.sml:

I would also like to do this in single.php as I only need this done on a specific post.

Any pointers?

Thanks,
::emp::
 


Stanley... that does not even go anywhere near my problem...

::emp::
 
FUCK!

I really, really hoped I could do this without writing a full fledged plugin.
ARGH!

Thank you, though.

::emp::
 
I ahven't tried it, but what about using output buffering, like <?php ob_start; the_content(); $string=ob_clear_buffer(); echo str_replace( $foo, $bar, $string ); ?>

I haven't tried it, and I'm not familiar with output buffering, but you might be able to do this in the single.php page.
 
I'm happy to try to help Emp but I want to make sure I understand what you're trying to do, otherwise what I have in mind might be completely useless to you.

So, in one particular post you want to be able to include some PHP code so that any visitors from "Referrer A" will see "Link A" and any visitors from "Referrer B" will see Link B? And the part you're struggling with is where to place the PHP code so that it executes inside the post and displays the correct URL dependant on referrer?
 
If you are just needing it for a particular post or page, you could use this plugin and just add the php directly into the page or post.
 
Thanks guys.

Actually, Argh01 pointed me in the right direction, so I will be writing my own WP plugin.
Not a lot of experience with the architecture behind WP, so I will just dive right in.

Basically, this is for tracking ad clicks, and I need to give the referrer to the redirect page.

Basically, whenever I link to href="link.php" I will replace it with href="link.php?q=keyword".

I am also in the process of writing an article about what I am trying to accomplish, will post it here and on the ape for sure.

thanks and +rep where due

::emp::
 
You don't need a full plugin to do this.

Just add something like this into your header:

PHP:
add_filter('the_content', 'replace_links');

function replace_links($text)
{
	return str_replace('WordPress', 'BLAH!', $text);
}
 
Status
Not open for further replies.