Custom PHP code in WordPress with Theme Template

Custom PHP code in WordPress with Theme Template

In WordPress you can easily add your own PHP code for certain pages via the themes.

To do this, copy the default template in the folder of the theme. Then you can specify a name for the template in the upper area:

/*
Template Name: Template_Name
*/

You can insert your own PHP code after the “normal” content of the page. This code looks something like this:


<?php if ( have_posts() ) : ?>

						<?php /* Start the Loop */ ?>
						<?php while ( have_posts() ) : the_post(); ?>

							<?php

							$post_display_option = get_theme_mod('post_display_option','post-excerpt');

							if($post_display_option == 'post-excerpt'){
								get_template_part( 'template-parts/content','excerpt');
							}
							else{
								get_template_part( 'template-parts/content','excerpt');
							}

							?>
							

Alternatively, you could replace the entire content area with your code.

You need help with your WordPress website? I will be happy to help you at reasonable hourly rates. You can reach me via my contact form.

Leave a Reply

Your email address will not be published. Required fields are marked *