A bit of PHP

Up a level : Programming
Previous page : Programmering 1 - JavaScript
Next page : Previous Up Next - Pun

I wanted to add links to the previous and next pages at the same level.To start with I added the Next Page, Not Next Post plug in. You can find information about the plugin at https://binarym.com/2009/next-page-not-next-post/.

I could then manually add [previous_page] and [next_page]  anchor texts on each page, but that would take time, and would not be particularly flexible. What I did instead was to create a child theme, and in that I added a filter to the functions.php file.

A filter is basically some process that the a page has  to go through before it is sent to the visitor.

In this case I want the filter to add  [previous_page] and [next_page] to the header and footer of the page, and also some vertical lines to frame the text. I also have a few pages where  I don’t want this to happen. I add the tag [pnp], but with n instead of p and p instead of n somewhere in the beginning of such a page. (I am somewhat proud of that I though of not writing the actual tag on this page.)

If such a tag is on the page it is overwritten, else texts are added at top of and at the end of the contents. This is the code:

add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
function theme_enqueue_styles() {
wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ );



function add_my_c1($content) {
$lineup='<a href=”http://media.properhoc.com/2017/01/lineup.png”><img class=”aligncenter size-full wp-image-391″ src=”http://media.properhoc.com/2017/01/lineup.png” alt=”” width=”654″ height=”3″ /></a>’;
$linedown='<a href=”http://media.properhoc.com/2015/10/linelow.png”><img class=”aligncenter size-full wp-image-409″ src=”http://media.properhoc.com/2015/10/linelow.png” alt=”” width=”654″ height=”3″ /></a>’;
$up_text = ‘Previous page: [previous_page] : Next page: [next_page]’.chr(0x0D).chr(0x0A).’ ‘.chr(0x0D).chr(0x0A).$lineup;
$low_text = $lineup.chr(0x0D).chr(0x0A).chr(0x0D).chr(0x0A).’Previous page: [previous_page] : Next page: [next_page]’.chr(0x0D).chr(0x0A).$lineup.’Last modified: Jan 22, 2017 @ 17:55‘;
$content =substr_replace($content,’     ‘,$pos,5);
} else{
$content = $up_text.$content.$low_text;
return $content;


I also added a time stamp of the time of the latest change in the footer.

Up a level : Programming
Previous page : Programmering 1 - JavaScript
Next page : Previous Up Next - PunLast modified: Feb 13, 2022 @ 21:48