(Wordpress) How can i get the full content of a post with the html tags - unstripped

17,380

Very simply add <?= apply_filters('the_content', $content); ?>

There are loads of references to this on Google.

EDIT So in this case:

$query = get_post(get_the_ID()); 
$content = apply_filters('the_content', $query->post_content);

echo $content;
Share:
17,380
CrikoC
Author by

CrikoC

I practice web development for the past several years. Mostly PHP, laravel and wordpress. My goal is to make plugins for wordpress that can be helpful to other developers. I'm also a guitarist and music composer, mainly in the progressive rock genre.

Updated on June 04, 2022

Comments

  • CrikoC
    CrikoC almost 2 years

    I'm using WordPress for my site with the qtranslate plugin and i'm trying to display language flags in each post.

    Qtranslate inserts html tags to the content and title like "!--:en-->" for each language that i used in each post

    So i need a conditional that checks which of these html tags are included in the content so i can print the specific flags

    something like this:

    function language_pick(){
        $qt_dir = "http://localhost/MY-SITE/wp-content/plugins/qtranslate-xp/flags/";
        $cr_url = "http://".$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
        $en_url = esc_html($cr_url."&lang=en");
        $fr_url = esc_html($cr_url."&lang=fr");
        $it_url = esc_html($cr_url."&lang=it");
        $es_url = esc_html($cr_url."&lang=es");
    
        $query = get_post(get_the_ID()); 
        $content = apply_filters('the_content', $query->post_content);
    
        if(get_permalink() != $cr_url) { echo '<a style="margin-left:15px;" href="'.$cr_url.'" /><img src="'.$qt_dir.'gr.png"></a>'; }
        if (strpos($content, '<!--:en-->') === true) {
             if(get_permalink() != $en_url) { echo '<a style="margin-left:15px;" href="'.$en_url.'" /><img src="'.$qt_dir.'gb.png"></a>'; } }
        if(strpos($content,'<!--:fr-->') === true) {
            if(get_permalink() != $fr_url) { echo '<a style="margin-left:15px;" href="'.$fr_url.'" /><img src="'.$qt_dir.'fr.png"></a>'; } }
        if(strpos($content,'<!--:it-->') === true) {
            if(get_permalink() != $it_url) { echo '<a style="margin-left:15px;" href="'.$it_url.'" /><img src="'.$qt_dir.'it.png"></a>'; } }
        if(strpos($content,'<!--:es-->') === true) {
            if(get_permalink() != $es_url) { echo '<a style="margin-left:15px;" href="'.$es_url.'" /><img src="'.$qt_dir.'es.png"></a>'; } }
    }
    
  • CrikoC
    CrikoC over 8 years
    Thank you for your answer! Where exactly should i put this in my code? the code above is in a function that i call in content-single.php, right after the_title()
  • CrikoC
    CrikoC over 8 years
    and to be a little more specific: $query = get_post(get_the_ID()); $content = $query->post_content; When i "echo" this (for check only), it's already stripped of html.
  • CrikoC
    CrikoC over 8 years
    Unfortunately it echos the content only in the default language so the conditional can't find html tags for other languages... Is there another way to grab the content from the database with the html tags as text?
  • ggdx
    ggdx over 8 years
    This is because you are simply copying and pasting what I have done. You don't have to echo it! Use $content however you wish! It will have whatever is (inc. html tags) in $query->post_content
  • CrikoC
    CrikoC over 8 years
    It works! instead of: if(strpos($title,'<!--:en-->') == true), This seems to do the trick: if(strpos($title,':en') == true)