Comments (9)
Hi Oliver,
The plugin should work on that function. See this. Can you give me more information about your setup? It could be that you're using this function outside of the Loop.
Cheers,
Philip
from subtitles.
Hi Philip,
I use it the very similar way (the same way, actually) as in Underscores' index.php
file. The function is outside the loop in there too.
If it needs to be in a loop, I can still modify my index.php
or use a filter hook, so no worries. I just thought this is a bug.
Regards,
Oliver
from subtitles.
The function is outside the loop in there too.
No, the function in _s is inside of a Loop. Either way, you can totally use this outside of your Loop; you'll just need to use one of the built-in template tags.
Closing this out as it's not a plugin bug.
Cheers!
from subtitles.
Hi Philip,
Thanks for explanation and help.
Doesn't the loop starts with while
? I thought so ;)
Regards,
Oliver
from subtitles.
Oops. You're totally right. I missed Automattic/_s@955cd14 when we added it into _s. :)
from subtitles.
So, I understand, this wouldn't work in _s either. For that particular use it is actually managable as we can find out the home (posts list) page ID. I will continue with custom solution then.
Thanks again!
from subtitles.
A custom solution is super-easy. It'd just be this:
<?php if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text">
<?php single_post_title(); ?>
<?php
if ( function_exists( 'the_subtitle' ) ) {
the_subtitle( '<p class="entry-subtitle">', '</p>' );
}
?>
</h1>
</header>
<?php endif; ?>
Is that not working?
from subtitles.
That actually wouldn't work as on is_home()
page it picks up the subtitle from the first post in the list.
Here is my custom solution that works when using single_post_title()
outside the loop:
/**
* Subtitles support in single post title outside the loop
*
* @param string $title
* @param object $post
*/
function themeslug_subtitles_single_post_title( $title, $post ) {
// Processing
if (
function_exists( 'get_the_subtitle' )
&& ! doing_action( 'wp_head' )
&& ! in_the_loop()
) {
$subtitle = get_the_subtitle( absint( $post->ID ) );
if ( ! empty( $subtitle ) ) {
$title = '<span class="entry-title-primary">' . $title . '</span>';
$title .= ' <span class="entry-subtitle">' . $subtitle . '</span>';
}
}
// Output
return $title;
} // /themeslug_subtitles_single_post_title
add_filter( 'single_post_title', 'themeslug_subtitles_single_post_title', 10, 2 );
from subtitles.
Boom, there ya go. Thanks for sussing this out and sharing. I'll roll these into the docs and make sure to share this thread with anyone else who runs into a similar issue. Cheers!
from subtitles.
Related Issues (20)
- Subtitle not shared on Facebook and co. HOT 3
- wp_seo_get_bc_title is deprecated HOT 13
- Maybe don't load CSS when 'subtitle_view_supported' filter is set to false HOT 1
- Gutenberg Support HOT 7
- Confirm bbPress Compatibility
- USER question re MarsEdit HOT 2
- Astra theme and comment title HOT 1
- Subtitles in custom page not showing HOT 6
- Not Showing Any More HOT 3
- Can't see subtitle box in Gutenberg HOT 1
- the_title echos both title and subtitle
- Option to keep HTML tags in subtitle fields
- Subtitle field not displaying on Page/Post add/edit form.
- Show subtitles in post loops HOT 2
- Examples
- the_subtitle logic check HOT 2
- Subtitles on Portfolio HOT 4
- multiple subtitles HOT 1
- Feature Request: above OR below HOT 5
- Changing Font Size HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from subtitles.