Can I do this?

  • madkad

    #6761

    Hi I am after adding some code to my home page but gotton a liitle confused as to how I am doing it

    ok I am using graphene theme, and using yoast wordpress SEO plugin

    and what I want to do on my home page is, when displaying posts check for the post meta description (for each the one post) and post it instead of the page content like it does now, the code below does just that, but it also still posts the post content?

    <?php
    $yoast_meta = get_post_meta($post->ID, '_yoast_wpseo_metadesc', true);
    if ( $yoast_meta ) {
    echo "$yoast_meta";
    } else {
    echo "do_action('graphene_after_post_content')";
    }
    ?>

    can anyone help me do something like this =

    if meta description is there, post it

    else

    if meta description is not there post 100 words of post content

    ==

    but then both need to still post a continue reading button to the post, hope you understand what I mean? thanks

    Prasanna SP

    #35497

    Why don’t you just put the same description in the Excerpt field?

    madkad

    #35498

    Excerpt field? whats that?

    have I been missing something all these years

    madkad

    #35499

    are just found that, the reason why I dont use it as the “continue reading” button doesnt show?

    edit, lol got that button to show, didnt realise it was in the options, but there is no option to limit the amount of text?

    madkad

    #35500

    the code

    <?php
    add_filter('excerpt_length', 'custom_excerpt_length');
    function custom_excerpt_length($length) {
    return 20; // Change this to whatever you want.
    }
    ?>

    doesnt seem to limit the length of the excerpt thats been added in that field? it will limit the standard content that is used from the pages (the auto excerpt)

    think I am going mad with this

    Mod

    Kenneth John Odle

    #35501

    That’s correct. You can use the above filter to alter the default excerpt length (which is 55 words), but this will always be overridden by whatever you add to the Excerpt field, whether it’s one word or a hundred words.

    madkad

    #35502

    OK thanks for your help on this 🙂

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.