Hello.
The plugin uses “the_content” filter to add links. The same function can be applied as a filter when showing custom posts, but there are 2 checks that need to be removed in order for the function to work.
There is a check that replace links only if it is the main loop, and if the content have at least 100 characters.
mmm…
Sorry but I don’t really get it.
It uses the the_content filter so it only searches the content field for keywords?
You are talking about custom posts (“The same function can be applied as a filter when showing custom posts”). But I’am talking about normal post types with custom fields echo’d in the single.php file.
I’am working on a recipe website. So the_content field is used for a recipe description. Then I’ve made several custom fields for ingredient’s, instructions, and so on…
And I want to plugin to search through the ingredient’s custom field and add custom links.
I am sorry, I was in a hurry. I wanted to say that you can add the same filter when you show custom fields.
Sorry but I’am new to php.
I’am using the Advanced Custom Fields to create custom fields. And now changed the filter to the following: (see: http://www.advancedcustomfields.com/resources/acfload_field/)
add_filter('acf/load_field/name=ingredienten', 'wpaal_add_affiliate_links',5);
My custom field name is “ingredienten”.
But it’s still not working.
This is how I echo’d the custom field in my single.php
<?php $ingredienten = get_post_meta($post->ID, 'ingredienten', true);
//Checking if anything exists for the key kcal
if ($ingredienten === "0" || $ingredienten) { ?>
<?php echo $ingredienten; ?>
<?php } //if there is nothing for songs then display
else { ?> <?php } ?>
Could you please give me some more information so I can get it working 🙂
How do I add excerpt field capabilities?
To enable the plugin to replace links on the excerpt, you should add this line in the main plugin file or in functions.php of your theme
add_filter('get_the_excerpt', 'wpaal_add_affiliate_links');
It will depend on how your theme display the excerpt. If it is not working then let me know what function your template is using for this.
I want it to display the excerpt using the the_excerpt() function. It doesn’t work properly, the page takes a long time to load and the add_filter(‘get_the_excerpt’, ‘wpaal_add_affiliate_links’); line of code is at the top. Maybe I’m not sure that I put the filter line of code in the correct location on the functions.php file. Thank you so much for getting back to me and helping me through this.
How many excerpts do you show on a page ( the one with loading problems ), can you share the link ?
You can change the filter to ‘the_excerpt’ instead of the_excerpt. The plugin was initially intended to run only on full content pages ( single posts and pages ), then I added the capability to run on homepage. There is some re-work to be done in order to function optimally if there are too many excerpts on the same page.