1

I am now the admin of our company site using Wordpress. We'd like to change some things on the home page, but unfortunately the items we want to change seem to be built in to the theme. I want to change the text overlay of our image slider. I've found the HTML that displays the text, but the actual text is being echoed from a PHP variable. Does anyone know how to track down the variable? It had to have been made by the original site designer. Basically, I'm interested in where: <h1><? echo the_title();?></h1> is pulling it's info. This must be pulling from an array of titles, as they change with the slides. I need to change a single one of those items within the array. If it helpes, the code is coming from page-templates/front-page.php

2

Child themes

The WordPress Way of modifying the theme's page-templates/front-page.php is to create a child theme, then duplicate this file in the child theme and make the modifications there. Your modified template file will be loaded instead of the parent theme's file.

This allows the parent theme to be updated without losing the modifications made to the template. The only real drawback here is that your child theme's copied template will not reflect any updates made to the parent theme's front-page.php. So, you'd have to manually update your modified template in the event that the parent theme's corresponding file is changed. It's best to only duplicate the parent theme's templates that you want to modify. This keeps the maintenance burden to a minimum.

the_title()

The way that the_title() works is, while in the WordPress loop, e.g.:

if ( have_posts() ) {
    while ( have_posts() ) {
        the_post(); ?>

        <h1><? the_title(); ?></h1>

        <?php
        // ...
    }
} else {
    // no posts
}

the_title() will echo the title for the current post in the loop. Note that echo the_title(); is incorrect since the output will be automatically echo'd. There is a similar function, get_the_title() that does not automatically echo the output.

the_title() is using the global $post variable which is set for each iteration in the loop using the_post(). Generally this is what is happening when the_post() is called within the loop:

the_post() --> 

WP_Query::the_post(); --> 

global $post;
$post = WP_Query::next_post();
WP_Query::setup_postdata( $post ); -->

$post = get_post( $post );

the_title() is then using get_the_title() which is grabbing $post->post_title, which is the title of the current post in the loop.

The Global Variables Codex page has a (partial) list of global variables used in WordPress.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.