How to add some javascript code under the post in Wordpress - php

I try to add some javascript code after the content and before the related news links but my javascript code shown after the related news.
I try to this with add my code here :
themes\themes_name\content_single.php :
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
<div class="entry-meta">
<?php accesspress_basic_posted_on(); ?>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_post_thumbnail(); ?>
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'accesspress-basic' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<div class="ads-baroot ads-desc">
**my Codes here...**
</div>

The Related news is probably parsed in <?php the_content(); ?>, your javascript-code is below that. Therefore the javascript result is displayed below the related posts.

Create your script file and add in theme default js folder and call in your theme function.php
function custom_scripts() {
wp_enqueue_script( 'customjquery', get_template_directory_uri() . '/js/customjquery.js', array(), '0001', true );
}
add_action( 'wp_head', 'custom_scripts' );

Related

WordPress Blog post layout different to each other

I have stumbled across a problem, which makes both versions of the Blog different to each other when I'm not signed in to my site. Basically, I have built the site through WP. Once I've signed in the layout of the Blog Post is designed the way it is supposed to be like; completely laid out aesthetically and streamlined (image 1).
Blog Post Example 1
However, I've checked the site afterwards to find that the layout has shifted the wrong way somewhat and that the blog text has blended into the footer, making things look undesirable (image 2).
Blog Post Example 2
I have done everything in terms of deleting the cache and webpages just to refresh the whole site.
The code itself as I've double/triple-checked it again and again, but still no cigar.
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title">', '</h2>' );
endif;
if ( 'post' === get_post_type() ) :
?>
</header><!-- .entry-header -->
<?php if ( has_post_thumbnail() ) { ?>
<?php the_post_thumbnail( array( 750, 750 )); ?>
<?php } ?>
<?php endif; ?>
<p class="article_date"><?php the_date(); ?></p>
<div class="blogTextExc">
<?php the_content(); ?>
Hello
</div>
<?php edit_post_link( 'Edit', '<div>', '</div>' ); ?>
</article><!-- #post-<?php the_ID(); ?> -->
Please help!!!!
You made some mistake in your code.
Header should be closed before if statement ( 'post' === get_post_type() )
Your code should look like this:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title">', '</h2>' );
endif;
?>
</header><!-- .entry-header -->
<?php if ( 'post' === get_post_type() ) :
if ( has_post_thumbnail() ) {
the_post_thumbnail( array( 750, 750 ));
}
endif; ?>
<p class="article_date"><?php the_date(); ?></p>
<div class="blogTextExc">
<?php the_content(); ?>
Hello
</div>
<?php edit_post_link( 'Edit', '<div>', '</div>' ); ?>
</article><!-- #post-<?php the_ID(); ?> -->

How to Add Post Thumbnail Image only on Home, Archive in Underscore Theme

Basically, I want to add thumbnail image on home page only, but it shows thumbnail image (Featured image) on single content also, which i don't want to load in single page.
I Want to add thumbnail like this:
( from here )
Theme: Underscore development theme
My content.php:
<?php
/**
* Template part for displaying posts
*
* #link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* #package DevWP
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title">', '</h2>' );
endif;
if ( 'post' === get_post_type() ) :
?>
<div class="entry-meta">
<?php devwp_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif; ?>
</header><!-- .entry-header -->
<?php devwp_post_thumbnail(); ?>
<div class="entry-content">
<?php
if ( is_single() ) {
the_content( sprintf(
wp_kses(
/* translators: %s: Name of current post. Only visible to screen readers */
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'devwp' ),
array(
'span' => array(
'class' => array(),
),
)
),
get_the_title()
) );
} else {
the_excerpt();
}
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'devwp' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php devwp_entry_footer(); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-<?php the_ID(); ?> -->
<hr>
I'm not sure if I understand correctly what your goal is, but if you want to show the featured image only on homepage and not for the rest of your pages, than you can try 2 things. 1st inside the content.php file to check if you're on the homepage with is_front_page() :
if(is_front_page()){
devwp_post_thumbnail();// I suppose this is echoing your thumbnail
}
The second thing you may do is to create a custom page template for your pages where you're not going to output the thumbnail.
Put This Code...
if( is_front_page() && is_home() ) {
devwp_post_thumbnail();
}

how to add <hr> on wordpress blogs view section

Hi guys i am new to WP development, this is my client site : bit.do/dFQtv i need to add hr line under each blog excerpt below read more section , how to do it, if i insert the line below read more button that shows in the single blog post page also
this is coding: (template-parts/content.php)
<?php
/**
* Template part for displaying posts
*
* #link https://codex.wordpress.org/Template_Hierarchy
*
*
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php
if ( is_single() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark" >', '</a></h2>' );
endif;
if ( 'post' === get_post_type() ) : ?>
<h4 class="meta text-muted">
<?php blog_posted_on(); ?>
</h4><!-- .entry-meta -->
<?php
endif; ?>
<!-- AddThis Button BEGIN -->
<div class="addthis_inline_share_toolbox_mzc3" style="margin-bottom:20px;" data-title="<?php the_title() ?>" data-url="<?php the_permalink(); ?>" </div>
<!-- AddThis Button END -->
</header><!-- .entry-header -->
<div class="entry-content">
<?php
the_content( sprintf (
/* translators: %s: Name of current post. */
wp_kses(__( 'Read more', 'blog' ), array( 'span' => array( 'class' =>
array() ) ) ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
) );
wp_link_pages( array(
'before' => '<div class= "page-links">'. esc_html__('Pages:', 'blog'
),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php blog_entry_footer(); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-## -->
(template-parts/content-page.php)
<?php
/**
* Template part for displaying page content in page.php
*
* #link https://codex.wordpress.org/Template_Hierarchy
*
*
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="entry-content"><hr>
<?php
the_content();
wp_link_pages(array(
'before' => '<div class="page-links">' . esc_html__('Pages:','blog'),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<?php if ( get_edit_post_link() ) : ?>
<footer class="entry-footer">
<?php
edit_post_link(
sprintf(
/* translators: %s: Name of current post */
esc_html__( 'Edit %s', 'blog' ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
),
'<span class="edit-link">',
'</span>'
);
?>
<hr>
</footer><!-- .entry-footer -->
<?php endif; ?>
</article><!-- #post-## -->
As per saw your theme you add your <hr> tag last line into your content.php inside the template-partsfolder.
like this:
<footer class="entry-footer">
<?php bfablog_entry_footer(); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-<?php the_ID(); ?> --><hr>
Double check you edit the correct file...I tried and it's working
Just add hr tag after closing the article tag and also you can write CSS for it to change width and color of it.
<?php
/**
* Template part for displaying page content in page.php
*
* #link https://codex.wordpress.org/Template_Hierarchy
*
*
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="entry-content"><hr>
<?php
the_content();
wp_link_pages(array(
'before' => '<div class="page-links">' . esc_html__('Pages:','bfablog'),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<?php if ( get_edit_post_link() ) : ?>
<footer class="entry-footer">
<?php
edit_post_link(
sprintf(
/* translators: %s: Name of current post */
esc_html__( 'Edit %s', 'bfablog' ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
),
'<span class="edit-link">',
'</span>'
);
?>
<hr>
</footer><!-- .entry-footer -->
<?php endif; ?>
</article><!-- #post-## -->
<hr class="abc" />

How to include HTML and [shortcode] inside PHP?

I have a wordpress website and I want to display this at the end of every blog post:
<h5 style="margin-bottom: 15px;margin-top:35px;"><em><strong>Text:</strong></em>
[shareaholic app="share_buttons" id="5374371"]
If I add this to single.php which shows the pages I want to modify, the shortcode won't work.
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
/* Featured Image */
if(has_post_thumbnail()) { ?>
<p class="post-thumbnail">
<?php the_post_thumbnail('full'); ?>
</p>
<?php }
the_content();
the_tags('<p>'.__('Tags:', 'sntheme'),', ','</p>');
/* Show post page links */
wp_link_pages( array( 'before' => '<p>' . __( 'Pages:', 'sntheme' ), 'after' => '</p>' ) );
?>
<h5 style="margin-bottom: 15px;margin-top:35px;"><em><strong>Text:</strong></em>
[shareaholic app="share_buttons" id="5374371"]
</article><!-- end post -->
Is there a workaround for this?
Yes - http://wordpress.org/plugins/shareaholic/installation/
<?php echo do_shortcode ('[shareaholic app="share_buttons" id="5374371"]'); ?>

In which .php file does wordpress print out the blog titles, dates, authors on index.php (main blog listing)

I was curious because I needed to make some modifications to the code markup of each of my displayed blog posts in the index.php listing.
I don't mean something like the_post(), I want to see the lowest level function where the raw html is being inputted. There is one line of html I need to append to all of my blogs so that the google authorship works.
I'm getting Warning: Missing required field "updated". in the rich snippet tool. No plugins serve this unfortunately.
This is what my theme's index.php looks like as of now:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', ( post_type_supports( get_post_type(), 'post-formats' ) ? get_post_format() : get_post_type() ) ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'loop-error' ); // Loads the loop-error.php template. ?>
?php endif; ?>
Here is the relevant part of content.php
<div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
<div class="post-content">
<?php echo apply_atomic_shortcode( 'entry_title', '[entry-title permalink="0"]' ); ?>
<?php echo apply_atomic_shortcode( 'byline', '<div class="byline">' . __( '[entry-published] · by [entry-author] · in [entry-terms taxonomy="category" before=""] [entry-edit-link before=" · "]', 'ascetica' ) . '</div>' ); ?>
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', 'ascetica' ), 'after' => '</p>' ) ); ?>
</div><!-- .entry-content -->
<?php echo apply_atomic_shortcode( 'entry_meta', '<div class="entry-meta">' . __( '[entry-terms taxonomy="post_tag" before="Tags: "]', 'ascetica' ) . '</div>' ); ?>
<?php do_atomic( 'close_entry' ); // ascetica_close_entry ?>
</div><!-- .post-content -->
</div><!-- .hentry -->
Thank you.
By default themes index.php file directly handle those from inside the loop. Your theme may have some difference.
Here is a visual of WordPress template files hierarchy http://codex.wordpress.org/images/1/18/Template_Hierarchy.png

Categories