- This topic has 7 replies, 3 voices, and was last updated 6 years, 3 months ago by
Leo.
-
AuthorPosts
-
December 30, 2019 at 7:31 am #1117581
Chris
Would you know how to automatically add nofollow to all affiliate links?
I read this article, but it didn’t help. It would give me a PHP error.
Any ideas on how to get this to work?
December 30, 2019 at 11:23 am #1117754David
StaffCustomer SupportHi there,
what was the error?
December 31, 2019 at 7:32 am #1118476Chris
Here’s the error I’m getting: http://prntscr.com/qhxlup
Here’s what I added in the functions.php file: http://prntscr.com/qhxlhu
December 31, 2019 at 10:19 am #1118584David
StaffCustomer SupportLooks like you got a bunch of errors in the code – if you compare your functions.php code to the original you will see a lot of the HTML has been escaped. You will need to correct the code so it matches that on the blog you got it from.
December 31, 2019 at 5:19 pm #1118712Chris
I don’t see anything missing (maybe because I don’t understand coding, haha). Could you correct the code:
// Add no-follow tags for specific domain strings function add_nofollow( $content ) { $az_url = "amazon1.com"; preg_match_all( '~<a.*>~isU', $content, $uri_match ); for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) { if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] ) && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] )) ) { $uri_change = trim( $uri_match[0][ $i ], ">" ); $uri_change .= ' rel="nofollow">'; $content = str_replace( $uri_match[0][ $i ], $uri_change, $content ); } } $az_url = "amazon2.com"; preg_match_all( '~<a.*>~isU', $content, $uri_match ); for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) { if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] ) && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] )) ) { $uri_change = trim( $uri_match[0][ $i ], ">" ); $uri_change .= ' rel="nofollow">'; $content = str_replace( $uri_match[0][ $i ], $uri_change, $content ); } } $az_url = "amazon2.com"; preg_match_all( '~<a.*>~isU', $content, $uri_match ); for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) { if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] ) && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] )) ) { $uri_change = trim( $uri_match[0][ $i ], ">" ); $uri_change .= ' rel="nofollow">'; $content = str_replace( $uri_match[0][ $i ], $uri_change, $content ); } } $az_url = "amazon2.com"; preg_match_all( '~<a.*>~isU', $content, $uri_match ); for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) { if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] ) && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] )) ) { $uri_change = trim( $uri_match[0][ $i ], ">" ); $uri_change .= ' rel="nofollow">'; $content = str_replace( $uri_match[0][ $i ], $uri_change, $content ); } } $az_url = "amazon2.com"; preg_match_all( '~<a.*>~isU', $content, $uri_match ); for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) { if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] ) && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] )) ) { $uri_change = trim( $uri_match[0][ $i ], ">" ); $uri_change .= ' rel="nofollow">'; $content = str_replace( $uri_match[0][ $i ], $uri_change, $content ); } } $az_url = "amazon2.com"; preg_match_all( '~<a.*>~isU', $content, $uri_match ); for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) { if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] ) && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] )) ) { $uri_change = trim( $uri_match[0][ $i ], ">" ); $uri_change .= ' rel="nofollow">'; $content = str_replace( $uri_match[0][ $i ], $uri_change, $content ); } } $az_url = "amazon2.com"; preg_match_all( '~<a.*>~isU', $content, $uri_match ); for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) { if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] ) && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] )) ) { $uri_change = trim( $uri_match[0][ $i ], ">" ); $uri_change .= ' rel="nofollow">'; $content = str_replace( $uri_match[0][ $i ], $uri_change, $content ); } } $az_url = "amazon2.com"; preg_match_all( '~<a.*>~isU', $content, $uri_match ); for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) { if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] ) && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] )) ) { $uri_change = trim( $uri_match[0][ $i ], ">" ); $uri_change .= ' rel="nofollow">'; $content = str_replace( $uri_match[0][ $i ], $uri_change, $content ); } } $az_url = "amazon3.com"; preg_match_all( '~<a.*>~isU', $content, $uri_match ); for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) { if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] ) && ( preg_match( '~' . preg_quote( $az_url ) . '~', $uri_match[0][ $i ] )) ) { $uri_change = trim( $uri_match[0][ $i ], ">" ); $uri_change .= ' rel="nofollow">'; $content = str_replace( $uri_match[0][ $i ], $uri_change, $content ); } } return $content; } add_filter( 'the_content', 'add_nofollow' );December 31, 2019 at 5:32 pm #1118713Leo
StaffCustomer SupportThis is something you will need to check with the code author unfortunately.
We can’t really help with custom functions that coming from an external source.
January 1, 2020 at 2:07 pm #1119299Chris
Thanks! Got it to work!
January 1, 2020 at 5:30 pm #1119379Leo
StaffCustomer SupportNo problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.