Created
August 25, 2016 11:21
-
-
Save joydevpal/cae57440b35a4805f6d2801287d4f3c7 to your computer and use it in GitHub Desktop.
Automatically add links to specific word defined through this function in Wordpress content or excerpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * auto link keywords in post content and excerpt | |
| */ | |
| function wcs_auto_link_keywords( $text ) { | |
| $replace = array( | |
| 'wordpress' => '<a href="http://www.wordpress.org">wordpress</a>', | |
| 'google' => '<a href="http://www.google.com">excerpt</a>', | |
| 'facebook' => '<a href="http://www.facebook.com">function</a>' | |
| ); | |
| $text = str_replace( array_keys($replace), $replace, $text ); | |
| return $text; | |
| } | |
| add_filter( 'the_content', 'wcs_auto_link_keywords' ); | |
| add_filter( 'the_excerpt', 'wcs_auto_link_keywords' ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment