Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Felix W.

    (@welly2103)

    Hi @joost-abrahams

    unfortunately there is no defined standard here. But since statuses are only stored as standard terms in WordPress you can get the status with the function get_term_by() and then access the attribute description there.

    I have created this as a small debugging page template. So you can test it.

    <?php
    
    /* Template Name: Example Template */
    
    echo '<pre>';
    $statusDescription = get_term_by('slug', get_post_status(), 'status');
    var_dump($statusDescription->description);
    echo '</pre>';
    exit;
    

    In a child theme, for example, you could work with it to access the description of the status.

    I hope this helps you.

    Greetings Felix

    Plugin Author Felix W.

    (@welly2103)

    Hi @joost-abrahams

    i have not heard from you again, so i am closing this thread and hope you have moved on with my reply.

    Greetings Felix

    • This reply was modified 1 year, 3 months ago by Felix W..
    Thread Starter joost-abrahams

    (@joost-abrahams)

    Thanks for the code @welly2103

    add_action('generate_before_page_title', function(){
        echo '<pre>';
    	$statusDescription = get_term_by('slug', get_post_status(), 'status');
    	var_dump($statusDescription->description);
    	echo '</pre>';
    },5);

    i did put this in my functions.php without

    exit;

    but it echo more then then status description:

    Like:

    string(21) "Needs to be proofread"

    https://www.mantablog.nl/aquarium-science/

    Thread Starter joost-abrahams

    (@joost-abrahams)

    oww sorry fixed it with:

    add_action('generate_before_page_title', function(){
        echo '<pre>';
    	$statusDescription = get_term_by('slug', get_post_status(), 'status');
    	echo($statusDescription->description);
    	echo '</pre>';
    },5);
    Plugin Author Felix W.

    (@welly2103)

    Hi @joost-abrahams

    nice to hear from you.

    The <pre> tag is only for testing purposes, you don’t necessarily need that. You can also just output the description with the hook used.

    With that this code would be enough:

    add_action('generate_before_page_title', function(){
    	$statusDescription = get_term_by('slug', get_post_status(), 'status');
    	echo($statusDescription->description);
    },5);

    Greetings Felix

    • This reply was modified 1 year, 3 months ago by Felix W..
    Thread Starter joost-abrahams

    (@joost-abrahams)

    Hi @welly2103

    I did pimp it up a bit, looks very nice now. i am a noob at php, css i understand better. The code used:

    add_action('generate_before_page_title', function(){
        echo '<figure class="wp-block-pullquote has-contrast-3-background-color has-background has-large-font-size">';
    	$statusDescription = get_term_by('slug', get_post_status(), 'status');
    	echo($statusDescription->description);
    	echo '</p></blockquote></figure>';
    },5);
    Thread Starter joost-abrahams

    (@joost-abrahams)

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Show post status description in theme’ is closed to new replies.