If the_title starts containing the same characters as the_content then

Right now I have a post that the_title and the_content starts with same text: "Hello world, we are WordPress…".

The above is just an example, every post has a different text.

What I want to do is basically, check if post content starts with the same few words as the title.

Then //do this.

else // do this.

I guess I need to use reggex here?

I would probably need to write how much of the first characters should match?

Maybe someone had the same situation could help me out.

thanks.

the_content() printing site title after page/post title and before its content

My pages are all showing the Site Title (from the Customizer) after the page or post title and before the "body" of the post. Troubleshooting by injecting lines of text to print before and after WordPress code narrows the source down to the the_content() call within the page template.

Here’s how the_content is called:

        ...         </header><!-- .entry-header -->          <div class="content entry-content">             <?php the_content(                 // Translators: %s: Name of current post. Only visible to screen readers.                 sprintf( esc_html__( 'Continue reading %s', 'bulmapress' ), '<span class="screen-reader-text">' . the_title( '', '', false ) . '</span>' )             );              wp_link_pages( array(                 'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'bulmapress' ),                 'after'  => '</div>',                 ) );                 ?>         </div><!-- .entry-content -->          <footer class="content entry-footer">         ... 

I’m a bit baffled because post_template.php where the_content() and get_the_content() are defined is a WordPress /includes file, not a parent theme file.

Should I be looking for some filter that’s been defined in the theme? TIA

Why escape if the_content isnt?

The built in function the_content runs through several filters, but does not escape output. It would be difficult for it to do so, as HTML and even some scripts must be allowed through.

When outputting, the_content seems to run through these filters (as of 5.0):

add_filter( 'the_content', 'do_blocks', 9 ); add_filter( 'the_content', 'wptexturize' ); add_filter( 'the_content', 'convert_smilies', 20 ); add_filter( 'the_content', 'wpautop' ); add_filter( 'the_content', 'shortcode_unautop' ); add_filter( 'the_content', 'prepend_attachment' ); add_filter( 'the_content', 'wp_make_content_images_responsive' );  (and)  add_filter( 'the_content', 'capital_P_dangit' ); add_filter( 'the_content', 'do_shortcode' ); 

It also does a simple string replace:

$ content = str_replace( ']]>', ']]&gt;', $ content );

And then get_the_content does a tiny bit of processing related to the “more” link and a bug with foreign languages.

None of those prevent XSS script injection, right?

When saving, the data is sanitized through wp_kses_post. But as this is an expensive process, I understand why it’s not used on output.

The rule of thumb for WordPress escaping is that everything needs to be escaped, regardless of input sanitation, and as lately as possible. I’ve read several articles saying this, because the database is not to be considered a trusted source.

But for the reasons above, the_content doesn’t follow that. Nor do the core themes (i.e. TwentyNineteen) add additional escaping on output.

So…why is it helping anything to escape elsewhere? If I were a hacker with access to the database, wouldn’t I just add my code to a post’s content?

Imagenes de the_content() no se ajustan al máximo de columna (WordPress y Bootstrap)

Tengo un problema, ya que al tener texto e imagenes en entradas o páginas de wordpress, estas no se ajustan al 100% del ancho de la página que deberían, sino que se ajustan al máximo de la misma imagen, generalmente mayor al de la página, y a su vez no son responsive.

Esto ocurre solo en el contenido de the_content()

<div class="contenido">   <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?>     <div class="container">       <div class="row">         <div class="col-lg-8" id="contenido" align="justify">             <?php the_content() ?>         <div class="fb-comments" data-href="<?php the_permalink() ?>" data-width="100%" data-numposts="5"></div>         </div>         <div class="col-lg-4 d-none d-lg-block" id="single-sidebar">           <?php get_sidebar( 'primary' ); ?>         </div>       </div>     </div>   <?php endwhile; ?> <?php endif; ?>  </div> 

He probado con ajustar el width=”100%” pero no funciona, sin embargo es solo en the_content() ya que las imágenes, por ejemplo, “destacadas” en cada entrada, incluyen la clase img-fluid (Está basada en Bootstrap).

¿Alguna forma de que puedan tener el ancho de la columna como máximo y sean responsive?