• Resolved Beee

    (@beee)


    I want to be able to ‘pull’ the custom description for a page, as set in the SEO plugin and use it in the header for og:description

    I want to use it for pages where the content field is not used, but only an iframe like http://www.djmonitor.com/live so I can’t use the excerpt

Viewing 15 replies - 1 through 15 (of 19 total)
  • Thread Starter Beee

    (@beee)

    After using this I saw the description is automaticly copied from the meta description, but I’ld still like to ‘fill’ that og:description tag, if possible.

    Plugin Contributor Joost de Valk

    (@joostdevalk)

    It is possible by using WPSEO_Frontend::metadesc() I think.

    Thread Starter Beee

    (@beee)

    I tested with
    WPSEO_Frontend::metadesc()
    $wpseo_front->metadesc()
    $wpseo_frontend->metadesc()
    nothing works

    WPSEO_Frontend::metadesc() inserts the normal meta tag (incl <meta> not just the value)

    $wpseo_front->metadesc() and $wpseo_frontend->metadesc() break the site

    Thread Starter Beee

    (@beee)

    anyone have a solution ???

    Looks like it works when you send false as an argument to the function.

    in other words WPSEO_Frontend::metadesc(false); – I’m using that right now to create my og:description tags based on the meta description from WordPress SEO.

    WPSEO_Frontend::title(); grabs the title as well 🙂

    Here’s the snippet i use to generate my open graph/Facebook tags with WordPress SEO

    <meta property="fb:admins" content="*Facebook ID*" />
    <mata property="og:author" content="Jens Ahrengot Boddum" />
    
    <?php
        	$og_title = get_bloginfo('name');
        	if (class_exists('WPSEO_Frontend')) $og_title = WPSEO_Frontend::title();
    
        	$og_description = get_bloginfo('description');
        	if (class_exists('WPSEO_Frontend')) $og_description = WPSEO_Frontend::metadesc(false);
    
        	$og_type = "article";
    		if (is_front_page()) $og_type = "website";
    
        	$og_url = get_permalink();
    	if (is_front_page()) $og_url = get_bloginfo('url');
    
        	echo '<meta property="og:type" content="' . $og_type . '"/>' . "\n";
        	echo '<meta property="og:url" content="' . $og_url . '"/>' . "\n";
        	echo '<meta property="og:site_name" content="' . get_bloginfo("name") . '"/>' . "\n";
        	echo '<meta property="og:title" content="' . $og_title . '" />' . "\n";
        	echo '<meta property="og:description" content="' . $og_description . '" />' . "\n";
    
        	if (has_post_thumbnail()){
    	    	global $post;
    	    	$img_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail');
    	    	echo '<meta property="og:image" content="' . $img_src[0] . '" />' . "\n";
    	    }
        ?>

    Thread Starter Beee

    (@beee)

    Cool. Will try it (when I get home)

    Thread Starter Beee

    (@beee)

    when i tested I got this error

    Missing argument 1 for WPSEO_Frontend::title(),
    called in /***/fb-include.inc on line 42 and
    defined in <b>/***/wp-content/plugins/wordpress-seo/frontend/class-frontend.php</b>
    on line <b>86</b>

    Thread Starter Beee

    (@beee)

    this works, so using that for now…. thnx

    if (class_exists('WPSEO_Frontend')) $og_description = WPSEO_Frontend::metadesc(false);
    echo '<meta property="og:description" content="' . $og_description . '" />' . "\n";

    Thread Starter Beee

    (@beee)

    I ran into a new issue… what if $og_description is empty, so I adapted it a bit…

    $default_description = "BLA BLA BLA";
    if (class_exists('WPSEO_Frontend'))
    {
    	$og_description = WPSEO_Frontend::metadesc(false);
    	if (!$og_description)
    	{
    		$og_description = $default_description;
    	}
    }
    else
    {
    	$og_description = $default_description;
    }
    echo '<meta property="og:description" content="' . $og_description . '" />' . "\n";

    Good to hear it works. By the way, I don’t think WPSEO_Frontend::metadesc(false) would ever return an empty string. As far as I know it grabs a description from within the content when you haven’t manually created one.

    I could be wrong though …

    Thread Starter Beee

    (@beee)

    it will if no description is entered (it did on my site)…
    that’s how I got to it…

    For me it just generates a meta description from my content when i don’t manually enter one.

    Thread Starter Beee

    (@beee)

    then you probably don’t show the meta tag at all…
    that makes sense. because I noticed if the tag description is not used (and i mean not show at all, empty is not ‘not used’), it takes the first x words/chars.

    Thread Starter Beee

    (@beee)

    I ran into a new problem (probably due to updates on the plugin).

    The site breaks on this piece of code (which you can see in the source code on http://www.berryplasman.com/tag/wordpress/ because if I remove it, it works fine). I think WPSEO_Frontend::metadesc(false); breaks it but I hope Yoast can answer this…

    The error is “Using $this when not in object context in /public_html/wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 555”

    if (class_exists('WPSEO_Frontend'))
    	{
    		$og_description = WPSEO_Frontend::metadesc(false);
    		if ($og_description)
    		{
    			echo '<meta property="og:description" content="' . $og_description . '" />' . "\n";
    		}
    	}
    	else
    	{
    		$og_description = $default_description;
    	}

    I got this error as well. I’m about to give up though and just go with the plugin defaults.

    I think you need to do something like this:

    $object = new WPSEO_Frontend();
    $og_title = $object->title();

    But I can’t quite get it to work.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘[Plugin: WordPress SEO by Yoast] Get the custom seo description for og:description’ is closed to new replies.