Pages like author page on our WordPress site are missing tag. Since the pages are being rendered by the default template index.php, I'm looking for a way to add tag in it. Below is index.php. Test code like echo $thumb . $alttext; doesn't seem to work not because the variable doesn't hold any value, but the code itself isn't working.
<?php get_header(); ?>
<div id="main-content">
<div class="container">
<div id="content-area" class="clearfix">
<div id="left-area">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$post_format = et_pb_post_format(); echo $post_format; ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post' ); ?>>
<?php
$thumb = '';
$width = (int) apply_filters( 'et_pb_index_blog_image_width', 1080 );
$height = (int) apply_filters( 'et_pb_index_blog_image_height', 675 );
$classtext = 'et_pb_post_main_image';
$titletext = get_the_title();
$alttext = get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true );
$thumbnail = get_thumbnail( $width, $height, $classtext, $alttext, $titletext, false, 'Blogimage' );
$thumb = $thumbnail["thumb"];
echo $thumb . $alttext;
et_divi_post_format_content();
if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) {
if ( 'video' === $post_format && false !== ( $first_video = et_get_first_video() ) ) :
printf(
'<div class="et_main_video_container">
%1$s
</div>',
et_core_esc_previously( $first_video )
);
elseif ( ! in_array( $post_format, array( 'gallery' ) ) && 'on' === et_get_option( 'divi_thumbnails_index', 'on' ) && '' !== $thumb ) : ?>
<a class="entry-featured-image-url" href="<?php the_permalink(); ?>">
<?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
</a>
<?php
elseif ( 'gallery' === $post_format ) :
et_pb_gallery_images();
endif;
} ?>
<?php if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) : ?>
<?php if ( ! in_array( $post_format, array( 'link', 'audio' ) ) ) : ?>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php endif; ?>
<?php
et_divi_post_meta();
if ( 'on' !== et_get_option( 'divi_blog_style', 'false' ) || ( is_search() && ( 'on' === get_post_meta( get_the_ID(), '_et_pb_use_builder', true ) ) ) ) {
truncate_post( 270 );
} else {
the_content();
}
?>
<?php endif; ?>
</article>
<?php
endwhile;
if ( function_exists( 'wp_pagenavi' ) )
wp_pagenavi();
else
get_template_part( 'includes/navigation', 'index' );
else :
get_template_part( 'includes/no-results', 'index' );
endif;
?>
</div>
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php
get_footer();
I'll try to be a little more pr?�cise in my answer that the comment allow me :)
When you want to customize your template or create a custom one, in Wordpress, you have 3 prossibilities :
1 - The WRONG way
You directly edit the templates files in your theme.
Why is this wrong? Because template, like plugins, are regularely updated, so if you directly edit your template's files, you risk to loose all your customisations when you'll update it.
To avoid this, you can create that we called a "child theme" in Wordpress.
2 - Create a Child theme
Simpliy putting, it is a nice solution to avoid the issue encountered on the point 1 ;)
A child theme inherit of the parent theme's functions and allow you to make some customizations/addition to it without the risk of loosing it (since when you update the parent theme, the child theme isn't touched).
Here is a complete tutorial of the principle: https://developer.wordpress.org/themes/advanced-topics/child-themes/
Note: imoo this require some level of knowledge in PHP because a wrong change can break you site.
3 - Using a theme builder
This is your case : on your site is installed the theme DIVI which allow you to customize you theme and create custom templates with no (or few at least) skills in developpment required.
This is why it is called a "theme builder". To name a few : Divi, Elementor, ...
Again in that case you can directly use the main theme or create a child theme (which is highly recommended).
That being said (wrote), to return to your situation, you found out that the file you need to edit is the "index.php". I doubt that because it seems to be an author page, so more likely "author.php"
Why?
Because in fact, ALL pages are processed by the "index.php" file as it is the central template file, but if a template corresponding to the content type exist in you theme it will be use instead (index.php is just a fallback in case you theme don't include a custom file for any particular case).
See this article for more information about template hierarchy: https://developer.wordpress.org/themes/basics/template-hierarchy/
BUT, since you use a theme builder, you do not need to edit thoses files.
As you are using Divi, I suggest you to watch some tutorials on how the theme builder works in practice.
In short, inside the template builder interface of Divi, you can create template(s), that you can affect to any type of content.
This video should guid you on the right direction: https://www.elegantthemes.com/documentation/divi/the-divi-theme-builder/
Hope it helps.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.