Hi ABTOP
The the_content
hook is what most plugins use because it is available in most themes. The good news is you can use any hook you want if it’s in the correct place in your theme. For you this was post_content_after
. This is not a WordPress hook (and therefore not available to most users).
Home
I don’t know how you set up the related posts with this plugin, but this plugin doesn’t use global variables to get or display the related posts.
global $related;
$related_posts = $related->show( get_the_ID() );
Saying the official documentation does not work is very far fetched. I understand you had some trouble displaying the related posts where you wanted, but the code you posted (not in the documentation) will produce errors for users without your custom setup (global object).
Also, you don’t have to remove a hook if you didn’t add it in the first place.
//first we remove the hook from the tail end of content
remove_filter( 'the_content', array($related, 'related_content_filter') );
-
This reply was modified 7 years, 8 months ago by keesiemeijer.
-
This reply was modified 7 years, 8 months ago by keesiemeijer.
The official advice doesn’t work, for it doesn’t remove the initial connection into the_content hook. I was getting duplicate insertions — one original, still working perfectly well and the second later displaying as shortcode. I was not able to get rid of the original insertion point until I used
remove_filter( 'the_content', array($related, 'related_content_filter') );
to counter your
// Add the related posts to the content, if set in options
add_filter( 'the_content', array($this, 'related_content_filter') );
per another piece of official documentation:
If a filter has been added from within a class, for example by a plugin, removing it will require accessing the class variable.
global $my_class;
remove_filter( 'the_content', array($my_class, 'class_filter_function') );
You are right about post_content_after
. Apparently this was custom for my theme and will not be available just for anybody. I should have double-checked it. Oops about it.
Generally plugins developers should not make concessions to lazy theme designers. Themes should support the fullest range of hooks, and those which do do not, should not be used.
At the end of the day, you would do well if you offered alternative hook to insert the Related links.
This plugin doesn’t insert the links (after the content). That’s why you have to use code in your theme’s functions.php file (or use a shortcode or function).
This code is not part of the plugin.
// Add the related posts to the content, if set in options
add_filter( 'the_content', array($this, 'related_content_filter') );
In what file did you find this?
If it’s causing duplicate insertions it’s better to remove that line instead of removing the filter.
Did you add it yourself or is this part of your theme? This plugin doesn’t have a file called related.php.
https://plugins.trac.wordpress.org/browser/related-posts-by-taxonomy/#trunk/includes