Last active
February 10, 2017 03:52
-
-
Save gatespace/fcf6516e98be84847bee2cfff1cb8514 to your computer and use it in GitHub Desktop.
WordPress 抜粋と「続きを読む」のカスタマイズ小ネタ ref: http://qiita.com/gatespace/items/61e40a5bdb30a4f80a83
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 | |
| /** | |
| * Filter the except length to 20 characters. | |
| * | |
| * @param int $length Excerpt length. | |
| * @return int (Maybe) modified excerpt length. | |
| */ | |
| function wpdocs_custom_excerpt_length( $length ) { | |
| return 20; | |
| } | |
| add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 ); |
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 | |
| /** | |
| * Filter the excerpt string link to the post. | |
| * | |
| * @param string $post_excerpt The post excerpt. | |
| * @param WP_Post $post Post object. | |
| * @return string (Maybe) modified "read more" excerpt string. | |
| */ | |
| function my_get_the_excerpt( $post_excerpt, $post ) { | |
| $more = sprintf( '<a class="more-link" href="%1$s">%2$s</a>', | |
| get_permalink( $post->ID ), | |
| __( 'Read More', 'textdomain' ) | |
| ); | |
| return $post_excerpt . $more; | |
| } | |
| add_filter( 'get_the_excerpt', 'my_get_the_excerpt', 10, 2 ); |
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 | |
| function remove_more_link_scroll( $link ) { | |
| $link = preg_replace( '|#more-[0-9]+|', '', $link ); | |
| return $link; | |
| } | |
| add_filter( 'the_content_more_link', 'remove_more_link_scroll' ); |
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 | |
| /** | |
| * Filter the excerpt "read more" string. | |
| * | |
| * @param string $more "Read more" excerpt string. | |
| * @return string (Maybe) modified "read more" excerpt string. | |
| */ | |
| function wpdocs_excerpt_more( $more ) { | |
| return '...'; | |
| } | |
| add_filter( 'excerpt_more', 'wpdocs_excerpt_more' ); |
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 | |
| $wpmp_conf['excerpt_mblength'] = 10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment