Search code examples
wordpressposts

Get spcific parts of post wordpress


So what im trying to do is to only get specific parts of my post to be shown.

Post Eg.

<h3>Heading</h3>
<p>Text about heading<p>
<h3>Heading-2</h3>
<p>Some other text about heading<p>

now what I want to be shown on the frontend is for e.g. only the paragraphs and not the heading.

Eg what to be shown.

<p>Text about heading</p>
<p>Some other text about heading</p>

Tried googling but couldn't really find something that matches my problem. Maybe I was asking the wrong questions.


Solution

  • Since you want specific part of your posts to be displayed, the easier and more logical way is to simply add a new field in your posts (perhaps use ACF it has a free for ever version or something similar) and then in the frontend get your field (in case you are using ACF) using for example this:

    echo esc_attr( get_field( 'mycustom_field_name' ) );
    

    An other solution would be to simple apply a css rule for anything you do not want to be visible, make sure to include the post class in the body of your posts to avoid hiding elements in other pages/post types.