Viewing 9 replies - 1 through 9 (of 9 total)
  • What did u use before?

    You asked this a couple of months ago ( http://wordpress.org/support/topic/two-titles-at-top-of-posts-after-customizr-update?replies=28 ) and were pointed there to a snippet on the themesandco site that shows how to do this in a future-proof way: http://www.themesandco.com/snippet/moving-single-post-metas-to-the-bottom-of-the-post/

    Thread Starter carissawp

    (@carissawp)

    Ok, I went into my file manager and I had to create a functions.php folder in my child theme because I didn’t have one yet. I pasted that snippet into the folder exactly as it reads in your link. The result was that my website was no longer viewable. As soon as I deleted the functions.php folder, my site became viewable again. Any idea what I did wrong?

    Did your functions.php in the child theme start with:

    <?php

    Thread Starter carissawp

    (@carissawp)

    No, it started with
    //we hook

    Do I need to add a line with

    <?php before that first line?

    acub

    (@acub)

    Yep. First line of any “pure” php file (as in a php file that gets included in other php files, as most of WP templates are) has to have

    <?php

    on its first line and nothing else. So your custom functions actually begin from line #2. Also, it is a very good practice to NOT exit php mode before EOF (end of file). So, even if you might find in some examples

    ?>

    on the last line of a php file it is better that you remove that bit. If you accidentally input a white space (tab, space, new line, etc…) after that bit of code your site might break and you won’t see it (because it’s white space) and you won’t know what’s breaking it). Also, the nastiest cases are those when the site only breaks on some pages (because that particular template is only loaded for certain queries).

    Thread Starter carissawp

    (@carissawp)

    So are you saying that for my file should I remove everything in that snippet after line 21??

    No. What he’s saying is this:
    child theme functions.php

    <?php
    //snippet

    Instead of

    <?php
    //snippet
    ?>

    So assuming you have just that snippet in your child theme functions.php, it (functions.php) has to look like this:

    <?php
    //we hook the code on the __before_body hook, which is executed before the <body> rendering.
    add_action ('__before_body' , 'move_single_post_metas');
    
    function move_single_post_metas() {
        //checks if we are displaying a single post. Returns false if not.
        if ( !is_single() )
            return;
        //we remove the original action hooked on '__post_metas'. tc_post_metas action is a method of the TC_post_metas class
        //We can access the instance of this class with a static property of this class that is a self instance.
        remove_action  ( '__after_content_title' , array( TC_post_metas::$instance , 'tc_post_metas' ));
    
        //we add the tc_post_metas action on a the __after_loop (check index.php file to see where this hook is called in the code)
        add_action ('__after_loop' , array( TC_post_metas::$instance , 'tc_post_metas'), 10);
    
        //Additional action to display an hr separator between content and metas.
        //We use the priority parameter to determine the rendering order of the action
        add_action ('__after_loop' , 'display_hr', 0);
    
        //this is a nested function (function in another function), allowed with PHP.
        function display_hr() {
            ?>
                <hr/>
            <?php
        }
    }
    Thread Starter carissawp

    (@carissawp)

    Success! It looks awesome. Thank you!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Move my metadata down’ is closed to new replies.