• Resolved Tadaki1989

    (@tadaki1989)


    Hi everybody,

    I’m currently modifying content.php. For some reasons, the_excerpt() does not display the excerpt properly: the first X words are missing (the number of missing words varies from post to post).

    At another place in the website, I use the function get_the_excerpt(), which works properly.

    I’m working on this place in the code:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    			<div class="entry-summary">
    				<?php the_excerpt(); ?>
    			</div><!-- .entry-summary -->
    		<?php else : ?>
    [...]

    Does somebody have any idea why the_excerpt() does not work right?

    Thanks,

    Tadaki

Viewing 14 replies - 1 through 14 (of 14 total)
  • what theme?
    do the posts have manual excerpts?
    is there any html at the begining of the posts?

    Thread Starter Tadaki1989

    (@tadaki1989)

    Hi juggledad,

    I’m using the vantage theme, but with a child theme.
    As far as I know, I did not do something with manual excerpts, so no. I once restricted the excerpt length to less words, but right now this function is commented out.

    The posts consist of an embedded pdf; before, the pdf’s text content is displayed in an invisible div to make the pdf content searchable.

    I’m also using the yarpp plugin for related posts; here, excerpts are displayed as well, and in the right way (using get_the_excerpt() ).

    If I include <?php the_excerpt(); ?> into content-single.php, the excerpt is displayed the right way as well.

    What is the url?
    does the issue happen on all posts in teh search or just some?

    Thread Starter Tadaki1989

    (@tadaki1989)

    Hi,

    unfortunately, it is an internal site…

    Interestingly, it does not happen to all posts of the search, only to some!
    But in all cases, three points are put in the beginning of the excerpt, even if the excerpt starts with the first word:

    “…A carbon footprint is historically defined as “the total sets of greenhouse gas emissions caused by an organization, event, product or person.” [Wright, L., Kemp, S., Williams, I. (2011)…”

    Is there someting common about those posts?

    can you give an example of what is in the post when you view it with the text editor

    Thread Starter Tadaki1989

    (@tadaki1989)

    I don’t see the mechanism behind… sometimes the posts are quite similar, but the excerpt of only one of them is displayed the wrong way.

    This is the text editor view of a post where the excerpt is displayed the wrong way; the excerpt starts here with the words “… requirements of” etc. I replaced the rest of the document’s text with […].

    <div class="hidden">CERTIFICATE OF REGISTRATION This is to certify that XXX Inc XXX Logistics 60 South XXXX Avenue XXX Arizona 85226 USA operates an Environmental Management System which complies with the requirements of ISO 140012004 for the [...]</div>
    <div id="pdfviewer"><iframe src="https://XXX/wp-content/pdf.js/web/viewer.html?file=https://XXX/wp-content/uploads/2015/10/ISO-Certificate.pdf" width="300" height="150"></iframe></div>

    Here the text editor view of a post where it works correctly:

    <div class="hidden">ENVIRONMENTAL MANAGEMENT SYSTEM ISO 140012004 This is to certify that XXX Logistics Excellence House XXX Road XXX Business Park XXX ST5 [...]</div>
    <div id="pdfviewer"><iframe src="https://XXX/wp-content/pdf.js/web/viewer.html?file=https://XXX/wp-content/uploads/2015/10/ISO-14001-Certificate.pdf" width="300" height="150"></iframe></div>

    Do you maybe need the html codes from “further above”? These two code snippets look the same for me.

    Do you maybe need the html codes from “further above”?

    is there more in the post previous to this code? If so, yes I’d like to see that too.

    could it be possible you are calling the code twice? here is something to try: change the code to this

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    			<div class="entry-summary">
    <?php echo 'about to do the excerpt<br>'; ?>
    				<?php the_excerpt(); ?>
    			</div><!-- .entry-summary -->
    		<?php else : ?>
    [...]

    Then see what shows when you do a search.

    Thread Starter Tadaki1989

    (@tadaki1989)

    is there more in the post previous to this code? If so, yes I’d like to see that too.

    I’m just getting some custom fields which are then attached to the post_title; so nothing which influences post_content.

    When I include your code, “about to do the excerpt” is attached in front of the excerpt, then followed by the three points. This is the case in both normal and “shortened” excerpts:

    about to do the excerpt
    …requirements of ISO 140012004 for the […]

    Thank you for you patience ??

    does the issue happen if you use the actual theme – i.e. not using the child theme?

    If it doesn’t, then it has to do with your customizations

    Thread Starter Tadaki1989

    (@tadaki1989)

    The problem exists also when I activate the main theme instead of the child theme.
    By checking this, I didn’t modify anything except to copy my custom search function to the functions.php of the main theme.

    So this leads me to beleive it is something about the post itself.

    What I would do is go to the post and view it in the text editor (not the visual editor). I would copy the entire text portion and save it to a text file. Next I would create a new post and paste the text into it and see if this post shows the same issue. If it does, I would edit the post taking ot the leading html bit by bit till the post excerpt shows up correctly and then you will have narrowed down what in the post is causing the issue

    Thread Starter Tadaki1989

    (@tadaki1989)

    I found the solution!!
    It has something to do with the plugin “Relevanssi” I use for better search results. Relevanssi highlights the matching keywords in the post content; when these matching keywords are further below, the excerpt is “shifted”.
    So, very simple solution in the end. Thank you very much for your efforts nevertheless!! ??

    my bad, debugging 101 is ‘disable ALL plugins and see if the issue goes away’

    Glad you found it, remember to mark this as resolved.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘the_excerpt(): First words are missing’ is closed to new replies.