Changeset 1556460
- Timestamp:
- 12/16/2016 11:50:31 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
speed-bumps/trunk/readme.txt
r1556451 r1556460 28 28 The simplest way to have Speed Bumps process all of your content and insert speed bumps into content everywhere is simply adding the filter following registration: 29 29 30 ``` 31 register_speed_bump( 'speed_bump_sample', array( 30 `register_speed_bump( 'speed_bump_sample', array( 32 31 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 33 32 )); 34 33 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 35 ` ``34 ` 36 35 37 36 This registration results in the `string_to_inject` value being injected at the first opportunity based on the default rules (e.g. on posts longer than 1200 characters, following the third paragraph OR following the paragraph which contains the 75th word, whichever comes later). 38 37 39 38 Let's say you wanted the speed bump higher in the content. You could modify the `from_start` parameter to declare that the speed bump can be inserted after the first paragraph (yes, like good engineers, we prefer zero-based indexing). 40 ``` 41 register_speed_bump( 'speed_bump_sample', array(39 40 register_speed_bump( 'speed_bump_sample', array( 42 41 'string_to_inject' => function() { return '<div id="speed-bump-sample"></div>'; }, 43 42 'from_start' => 0, 44 43 )); 45 ` ``44 ` 46 45 47 46 You can also selectively insert speed bumps into a string of content by calling Speed Bumps directly: 48 47 49 ``` 50 echo insert_speed_bumps( $content_to_be_inserted_into ); 51 ``` 48 `echo insert_speed_bumps( $content_to_be_inserted_into ); 49 ` 52 50 53 51 == Frequently Asked Questions == … … 70 68 Simple, stupid example: You have a speed bump called "rickroll" which inserts a beautiful musical video throughout your content. You _really_ need this viral bump (publisher's words, not yours) so you disable minimum content length and the rules regarding acceptable speed bump distance from start/end of the post. Greedy! 71 69 72 ``` 73 register_speed_bump( 'rickroll', array( 70 `register_speed_bump( 'rickroll', array( 74 71 'string_to_inject' => function() { return '<iframe width="420" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>'; }, 75 72 'minimum_content_length' => false, … … 78 75 )); 79 76 add_filter( 'the_content', 'insert_speed_bumps', 1 ); 80 ` ``77 ` 81 78 82 79 But, maybe that's a little too extreme. You want to show it in certain situations, say, only when the previous paragraph contains the phrase 'give {something} up'. Here's how you would achieve that: 83 80 84 ``` 85 add_filter( 'speed_bumps_rickroll_constraints', 'give_you_up', 10, 4 ); 81 `add_filter( 'speed_bumps_rickroll_constraints', 'give_you_up', 10, 4 ); 86 82 87 83 function give_you_up( $can_insert, $context, $args, $already_inserted ) { … … 91 87 return $can_insert; 92 88 } 93 ` ``89 ` 94 90 95 91 You could also disable it altogether with this filter (although why you would disable so soon after addition, only Rick Astley himself could answer): 96 92 97 ``` 98 add_filter( 'speed_bumps_rickroll_constraints', '__return_false' ); 99 ``` 93 `add_filter( 'speed_bumps_rickroll_constraints', '__return_false' ); 94 ` 100 95 101 96 = How to remove default rules? = … … 103 98 Each rule is hooked to that speed bump's "constraints" filter. To remove a rule, simply remove the filter which defines that rule, like these lines which remove the default rules for your speed bump: 104 99 105 ` ``100 ` 106 101 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::content_is_long_enough_to_insert' ); 107 102 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Text\Minimum_Text::meets_minimum_distance_from_start' ); … … 110 105 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Content\Injection::meets_minimum_distance_from_other_inserts' ); 111 106 remove_filter( 'speed_bumps_{id}_constraints', '\Speed_Bumps\Constraints\Elements\Element_Constraints::meets_minimum_distance_from_elements' ); 112 ` ``107 ` 113 108 114 109 == Changelog ==
Note: See TracChangeset
for help on using the changeset viewer.