-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DRI - the_excerpt within the_content #153
Conversation
`the_content` filter is potentially applied to related posts as well. The related posts section uses `the_excerpt()` and `the_content` filter gets applied when there is no custom excerpt is set for the post. Let's say that I show 3 related posts, 2 x has Enlighter block and 1 x doesn't doesn't have Enlighter block, then variable `$T->_hasContent` of the plugin is set to `false` and the plugin doesn't add the necessary resources, because that one related post doesn't have enlighter within it. This code checks if the current content being processed is excerpt. If it's excerpt (related posts), then just return the content. If not, then do the actual fun stuff. The reason why it was working on twentynineteen is that there wasn't any other post using `the_excerpt()` function on the theme. E.g. related posts
Added `{}` and removed whitespacing and add a comment to explain what is being done
the problem is the use of i'll check it soon but i'm not sure what the code should do....it seems that the_content/the_excerpt are not used in the intended way... |
Full excerpt from the guys that support my theme: Did some tests and found out that Let's say that "Golden Gate Bridge" post has Enlighter block, but So the solution part is here. To make
This code checks if the current content being processed is excerpt. If it's excerpt (related posts), then just return the content. If not, then do the actual fun stuff. The reason why it was working on twentynineteen is that there wasn't any other post using |
ah ok, now i'm understanding whats happening: the in this case we need a different solution: a singleton flag which can only set 1-times to the disadvantage of the solution would be that EnlighterJS resources may added to pages where no Enlighter codeblocks appear (because they exists in related post on the page). |
Ahhhh, yes I see what you're saying too! Yes, a single flag would be most ideal 😄 |
that would be my prefered version: // EnlighterJS Code detection
add_filter('the_content', function($content) use ($T){
// block overrides caused by multiple calls to the_content filter
// is the filter called regular to display the content ?
if (!$T->_hasContent && in_the_loop() && is_main_query()){
// contains enlighterjs codeblocks ?
$T->_hasContent = (strpos($content, 'EnlighterJSRAW') !== false);
}
return $content;
}, 9999, 1); |
would you like to try it ? :) |
Doing it now 😉 |
That seems to be working very well!!! :) One quick side question - why is mootools from jsdelivr a minor version behind all others? I'm currently enqueue-ing it manually (https://cdn.jsdelivr.net/gh/mootools/[email protected]/dist/mootools-core.min.js) and it's working OK. I'll switch back to using the plugin enqueued version so that it's only enqueued when necessary, but just wondered why it's v1.5.0 not v1.6.0 like all the other CDN's?
|
because jsdelivr is not always up to date....as i updated to 1.6.0 this version was not available yet! |
the_content
filter is potentially applied to related posts as well. The related posts section usesthe_excerpt()
andthe_content
filter gets applied when there is no custom excerpt is set for the post.Let's say that I show 3 related posts, 2 x has Enlighter block and 1 x doesn't doesn't have Enlighter block, then variable
$T->_hasContent
of the plugin is set tofalse
and the plugin doesn't add the necessary resources, because that one related post doesn't have enlighter within it.This code checks if the current content being processed is excerpt. If it's excerpt (related posts), then just return the content. If not, then do the actual fun stuff.
The reason why it was working on twentynineteen is that there wasn't any other post using
the_excerpt()
function on the theme. E.g. related posts