Coder Social home page Coder Social logo

Comments (9)

philiparthurmoore avatar philiparthurmoore commented on July 17, 2024

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.

webmandesign avatar webmandesign commented on July 17, 2024

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.

philiparthurmoore avatar philiparthurmoore commented on July 17, 2024

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.

webmandesign avatar webmandesign commented on July 17, 2024

Hi Philip,

Thanks for explanation and help.

Doesn't the loop starts with while? I thought so ;)

Regards,

Oliver

from subtitles.

philiparthurmoore avatar philiparthurmoore commented on July 17, 2024

Oops. You're totally right. I missed Automattic/_s@955cd14 when we added it into _s. :)

from subtitles.

webmandesign avatar webmandesign commented on July 17, 2024

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.

philiparthurmoore avatar philiparthurmoore commented on July 17, 2024

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.

webmandesign avatar webmandesign commented on July 17, 2024

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.

philiparthurmoore avatar philiparthurmoore commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.