• Resolved magicalwonders

    (@magicalwonders)


    I’m using the latest WP 4.4 and I’d like to include a block of text at the top of the Posts page that is static and remains in place at the top as posts are added below it.

    I’ve considered making a sticky post, but this doesn’t really work well for what I need. I’d like the usual meta data showing with normal posts, such as “posted by Admin” etc, but I don’t want that showing with my introductory text at the top! So unless I can remove meta date for just the sticky post, that’s not going to be suitable. ??

    Does anyone have any ideas on how I can do this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • You could use a filter to do that.

    https://codex.www.ads-software.com/Plugin_API/Filter_Reference

    What the URL of the page in question?

    Thread Starter magicalwonders

    (@magicalwonders)

    Hello Radices,

    Thanks for the codex link. The page is about three miles long, so not sure which part will help me. I’m not really familiar with filters, or where they are used.

    The url of the page is here – https://internetsquad.co.uk/magic-stuff/
    I’m working on the site locally using WAMP and the url above is only a test environment on a live server. The site will eventually go live on a different domain. ??

    Sorry this might be better.

    https://codex.www.ads-software.com/Plugin_API#Filters

    First thing is you should create a child theme and do your customization on it so you do not lose the changes if you update the parent theme.

    https://codex.www.ads-software.com/Child_Themes

    The concept is that you can put a function in the child themes functions.php file that will add content to a page. Throughout WordPress there are hooks that will fire your code at specific times. So you need to find the correct hook to add your text to the top of the blog roll page.

    https://codex.www.ads-software.com/Function_Reference/the_content

    Here is an example of adding text to the bottom of every post. The if(is_single()) is for individual blog posts. Not sure right off what it should be for the blog roll page but look here.

    https://codex.www.ads-software.com/Function_Reference/is_singular

    add_filter ('the_content', 'insertSubscribeNewsLetter',5);
    function insertSubscribeNewsLetter($content) {
       if(is_single()) {
          $content.= '<h3>Sign up for free updates to make your life more epic!</h3>';
    
       }
       return $content;
    }

    EDIT:
    Since you want to put your message at the top you’d do it this way

    $custom_content = 'YOUR CONTENT GOES HERE';
        $custom_content .= $content;
    }
    return $custom_content;

    You could also edit the themes template page and put the code (text) directly in it.

    Thread Starter magicalwonders

    (@magicalwonders)

    Ok that’s great, thank you. I already have a child theme created, so i’m half way there!

    I’ll study your references over the weekend and hopefully get this working. Thanks again!

    Your welcome. Let us know if you need more help or mark this resolved when you get it working please.

    Thread Starter magicalwonders

    (@magicalwonders)

    Ok. I’ve got this working locally now, but by a slightly different method.

    I’ve copied the index.php file into the child theme and added my block of text above the code <?php if ( have_posts() ) : ?>

    This seems to work really well, so I don’t think I need to edit the functions file now. ??

    That’s great! Editing template files is a bit easier to start with but note that if you change themes you will need to do it over again, where as the functions method would work with any theme … you’d just have to copy your functions.php file over.

    Good job!

    Thread Starter magicalwonders

    (@magicalwonders)

    Thanks. I’ll remember about the theme change issue. ??

    I’ll mark this thread as resolved now.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How do I add a non-post paragraph of text at top of Post page?’ is closed to new replies.