WordPress theme is not allowing HTML in my content - php

I have a blog running on MemberPress and I am trying to add a in the content of my blog posts to add a new paragraph.
When I add the < br / > it does not work, see the image.
My theme does not seem to be rendering the HTML in the post. I tried the visual editor and the text editor.
Do I need to add something to my PHP code to make my posts show the HTML I enter?
Here is the PHP for the blog content:
<div class="entry-content">
<div class="entry-meta ht-post-info">
<?php total_posted_on(); ?>
</div><!-- .entry-meta -->
<header class="entry-header">
<?php the_title( sprintf( '<h2 class="entry-title">', esc_url( get_permalink() ) ), '</h2>' ); ?>
</header><!-- .entry-header -->
<div class="entry-categories">
<?php echo total_entry_category(); // WPCS: XSS OK. ?>
</div>
<!-- .entry-content -->
<div class="entry-summary" style="margin-left: 13%; margin-top: 2%;">
<?php
if(has_category('premium', $wp_query->post->ID)){
echo do_shortcode("[mepr-active rule='282' ifallowed='show' unauth='message' unauth_message='This content is for authorized members only.']". esc_html(wp_trim_words( get_the_content(), 490 ))."[/mepr-active]");
}else{
echo esc_html(wp_trim_words( get_the_content(), 490 ));
}
?>
</div>
</div>
This is the post that showing 3 lines on one:

The wp_trim_words function you're using strips all HTML tags out.
https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-includes/formatting.php#L3359
$text = wp_strip_all_tags( $text );
(Even if it didn't, your use of the esc_html function after it would also break your HTML tags in the post.)

Related

get_template_part - Wordpress not working

I am trying to place the content of the about page inside a div on the header , the template part is located on folder template-parts/content-about.php
on the header the code is:
<div id="slideOut">
<div class="slideout-content">
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', 'about' );
endwhile; // End of the loop.
?>
<?php include 'content-about.php'; ?>
</div><!-- .slideout-content -->
</div>
And the content-about.php looks like this:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<?php
the_content();
wp_link_pages(
array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'about' ),
'after' => '</div>',
)
);
?>
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
The issue is that is showing on the div the same content as the current page for example if I'm located on home page it shows only the content of the home page inside the div when it should always show the content of the about page.
why is not working?
Thanks
get_template_part() is working as expected. Your content-about.php is included normally.
However, it prints the content of the current post/page because you're calling the_content().
You could replace the_content() with get_the_content(), passing the post id of your about page as the third parameter.
Note that:
An important difference from the_content() is that get_the_content() does not pass the content through the the_content filter. This means that get_the_content() will not auto-embed videos or expand shortcodes, among other things.
So, you might want to use apply_filters() like this:
<?php
echo apply_filters( 'the_content', get_the_content( null, false, $about_page_id ) );
// where $about_page_id is the post id of your about page
You don't even need the get_template_part for this if you don't want.
You can do this:
<div id="slideOut">
<div class="slideout-content">
<?php echo get_the_content('','','your-about-page-id-here'); ?>
</div><!-- .slideout-content -->
</div>
get_template_part() is a way to include files with markup that may rely on the loop, but keep things separated. You don't necessarily need it here.
You can also use:
echo get_post_field('post_content', your-post-id-here );

Add Columns to Understrap / Underscores Blog Page Template Posts

I'd like to customize the Underscores Wordpress Theme Blog Template to include columns around each blog post entry.
Ideally, these would become a grid of posts with pagination, but right now I'm just trying to get the grid to work.
This is from the content.php file:
<?php
/**
* Post rendering content according to caller of get_template_part.
*
* #package understrap
*/
?>
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ),
'</a></h2>' ); ?>
<?php if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php understrap_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif; ?>
</header><!-- .entry-header -->
<?php echo get_the_post_thumbnail( $post->ID, 'large' ); ?>
<div class="entry-content">
<?php
the_excerpt();
?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'understrap'
),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php understrap_entry_footer(); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-## -->
</div>
Thanks for your help!
i assume you talking about UnderStrap, not about Underscores, right?
To add the Bootstrap grid (http://getbootstrap.com/docs/4.1/layout/grid/) to your article/blog view you have to do two things:
Step 1
Wrapping an outside row around your loop.
To do this:
open the themes index.php and search for:
<main class="site-main" id="main">
Add the opening right behind this so that you have this:
<main class="site-main" id="main"><div class="row">
Now add the closing tag right before the closing tag:
</div></main>
Step 2
While the outside row wrapper needs to be added just once around all articles you need to add a Bootstrap col class plus the right size variable to your loop-templates/content.php file. So that it applies to all articles in your loop.
Open the file and add this:
<div class="col-6">
right before the opening <article> tag.
The col-6 class means "use 6/12 of space, e.g. 50%.
So you will have two articels side-by-side.
Of course you can use col-4 (4/12=33.33%) to have three articles side-by-side etc.
Depending on your needs another good starting point would be to utilize the Bootstrap card-deck component:
http://getbootstrap.com/docs/4.1/components/card/#card-decks

Not able to remove WordPress page title without removing the content aswell

I am making a WordPress theme with the framework from Underscores.me.
I do not wish to show the page title on pages. So I thought I could use some simple CSS to do it:
.entry-title {display:none;}
But doing this also removes all content on the page basically just showing an empty page.
Then I thought I could remove the title by deleting this in my theme:
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
But by removing the above also removes all content from showing.
Its like the title has to be shown in order to show content. I never had this problem before and I have developed a few themes with Underscores.me. But it is like the new version has to show page titles in order to show the content.
Have anyone any idea what to do?
I am running on a localhost so I cant show my problem but I am using the newest theme from Underscores.
Even if I install a "disable page title" plugin the plugin also removes the content when disabling the title.
I really hope someone had this problem before! :)
Extra info:
This is how the page.php looks like:
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content', 'page' ); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
<?php endwhile; // End of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
This is the template it calls for:
<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">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'open2day' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
As I said, if I remove the title with CSS it also removes the content.
please use !important in your css like below
hope this will work.
.entry-title {display:none !important;}
When you comment out the following line:
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
your page no longer has an h1 element of class "entry-title".
Your CSS is expecting this element to be on your page, so unless you want to edit your CSS, you can just add the following empty element:
<h1 class="entry-title"></h1>
This should solve your problem and allow the content to be displayed whilst hiding the page title.

Wordpress - get post content in new div

I am trying to use a post image/thumbnail in one div and the content in a new div on a custom layout. Having trouble trying to get the content after the image to show.
This works in getting my post title and image into the desired layout but is not showing the image caption–
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h3 class="title no-underline">', '</h3>' ); ?>
</header><!-- .entry-header -->
<div class="news-images">
<div id="news-swiper" class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" data-caption="">
<div class="entry-content news-item-copy">
<?php
$get_description = get_post(get_post_thumbnail_id())->post_excerpt;
the_post_thumbnail();
if(!empty($get_description)){//If description is not empty show the div
echo '<div class="image-captions">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>';
}
?>
</div>
</div>
</div>
</div>
</div>
<div class="news-sharing">
<?php wpsocialite_markup(); ?>
</div>
This is where I am trying to get the remaining post content and having issues.
<div class="news-item-copy">
<?php the_excerpt(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'themeName' ),
'after' => '</div>',
) );
?>
</div>
</article>
I've used <?php the_excerpt(); ?> just to place the content in it's desired location but obviously because it's an excerpt it's not showing the full content. The idea was to place the featured image/thumbnail with caption on top, the social sharing in the middle and the content last.
I think you want to replace the_excerpt() with the_content()
http://codex.wordpress.org/Function_Reference/the_content
You re passing thumbnail id inside get_post,you have to pass post id not thumbnail id in that function
$get_description = get_post(get_post_thumbnail_id())->post_excerpt;
Or simply echo the_content(); it will print post content & if you want to display some limited content
then use
substr(the_content(),0,150) it will display only 150 character

Wordpress display read more in the entry footer

here is what I want to do:
I have a blog post which I want to display only to a specific point. So in the post I put
<!--more-->
on the right position.
My content.php looks like this:
<div class="entry-content">
<?php the_content('read more'); ?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php mytheme_entry_footer(); ?>
</footer><!-- .entry-footer -->
The "read more" link gets displayed right after the content where it should be. But how can I display it inside the entry footer with the "Comment" link?
Is there a solution with the excerpt?
<?php the_excerpt(); ?>
I think this would even be better because I wouldnt need to put the line in every post.
You can remove the 'read more' by using the following filter in your functions.php:
add_filter( 'the_content_more_link', 'remove_more_link', 10, 2 );
function remove_more_link( $more_link, $more_link_text ) {
return;
}
Now you can create your own read more link inside entry-footer:
<footer class="entry-footer">
<a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>">Read more</a>
<?php mytheme_entry_footer(); ?>
</footer><!-- .entry-footer -->
Edit:
In comments below the following question was asked:
I used the_excerpt() instead of the_content(). Is it possible to only display the link if the post is actually too long?
You can do this by checking if the excerpt is different from the content. If this is the case (so there is more content than the excerpt is showing) you can show the read more link:
<?php if ( get_the_content() != get_the_excerpt() ){ ?>
<a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>">Read more</a>
<?php } ?>
I use one workaround:
//REMOVE 'MORE' LINK AND HARDCODE IT INTO PAGE - TEASER JUST PLAIN ELLIPSIS
function modify_read_more_link() {
if ( is_front_page() ) {
return '...';
} else {
return '</div><footer class="clearfix"><a class="mg-read-more" href="' . get_permalink() . '">Continue Reading <i class="fa fa-long-arrow-right"></i></a>';
}
}
add_filter( 'the_content_more_link', 'modify_read_more_link' );
Explanation: for front page I have a short overview only clickable in the post title. And for blog list (after else in the above function.php ):
<article>
<header></header>
<div>
<?php the_content(); ?>
</footer>
</article>
In which you can notice missing div closing and footer opening tags. It is a bit messi, but it brings the original Wordpress Teaser into next division.
Thankyou for reading.

Categories