I’m not sure I’m fully understanding, but here we go anyway. 😀
If your main goal is to filter post content and look for links that need to be changed ( if they meet a certain set of criteria ) without the author knowing about it, then try this:
In your functions file:
function alter_links_in_posts( $the_content ) {
// Do whatever you want to the content here:
/*
* Now anywhere you use the_content(), you'll get the
* modified version you whipped up in this function.
*/
return $the_content;
}
add_filter( 'the_content', 'alter_links_in_posts' );
Shortcodes may also be applicable depending on what exactly you’re trying to do.
Hopefully, this can get you started, at least. Just ask if any of this doesn’t make sense or I misunderstood you. 🙂
Thanks a lot for your feedback in the main time I have been fixing this issue, and mainly as you suggested. Just one more thing what I would like to know. Is it possible to make this without to include the filter function in the template file. Is it possible to make a plugin for this? I’m new to wordpress
It’s definitely possible to make this a plugin. In fact, it’s a great idea.
Here’s what you could do:
<?php
/*
* Plugin Name: Filter Post Author Links
* Plugin URI: http://codespanker.wordpress.com
* Description: This plugin allow anchor tags in posts to be filtered/altered before output by the_content().
* Author: Spencer Cameron - pippercameron@gmail.com
* Version: 1.0
* Author URI: http://codespanker.wordpress.com
*/
function alter_links_in_posts( $the_content ) {
// Do whatever you want to the content here:
/*
* Now anywhere you use the_content(), you'll get the
* modified version you whipped up in this function.
*/
return $the_content;
}
add_filter( 'the_content', 'alter_links_in_posts' );
?>
Copy-paste this code into a file and name it whatever-you-want.php. Make sure you put this file in wp-content/plugins/. Once you do that, it will be available to activate from your plugins menu in WP admin. 😀