0

Hi Need help to change wordpress meta og urls with wordpress shortcodes... Below is meta I need implemented and I only need to apply to certain post ids... Not the entire website...

Note -- All the brackets are shortcodes...and the og:image has a shortcode added appended to the url..

<meta name="description" content="[user_first_name] is the winner of XYZ.">
  <meta property="og:description" content="[user_first_name] has won the game... nobody can beat him...or? Take your chance.">
  <meta property="og:title" content="See if you can beat [user_first_name]">
  <meta property="og:site_name" content="[site-name]">
  <meta property="og:type" content="profile">
  <meta property="og:url" content="[current_url_of_page]">
  <meta property="profile:username" content="[wordpress_user_name]">
  <meta property="fb:app_id" content="138782406329521">

  <meta property="og:image" content="https://example.com/share-image?pc=false&ct=Soulja&np=false&piu=[user_pic_url]">
  <meta property="twitter:image" content="https://example.com/share-image?pc=false&ct=Soulja&np=false&piu=[user_pic_url]">

  <meta name="twitter:site" content="@MyCompany">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:app:country" content="[Country_code]">
  <meta name="twitter:app:name:iphone" content="My Company">
  <meta name="twitter:app:id:iphone" content="711923939">
  <meta name="twitter:app:name:ipad" content="My Company">
  <meta name="twitter:app:id:ipad" content="711923939">
  <meta name="twitter:app:name:googleplay" content="My Company">
  <meta name="twitter:app:id:googleplay" content="com.example">
1

In your theme, you'll need to most likely modify the "header.php" template. It should include the tag of html output for every page of the site.

Within the tag, you can use a conditional call to check the result of both the queried object type and id using: get_queried_object().

For instance, you would have some php like this in the tag of header.php:

<?php
$queried_object = get_queried_object();

//check to see that the object is not an archive page or category page, but an individual post or page
if(! empty( $object->post_type )) {

    //conditionally check that it is the specific page you want to target
    if($object->queried_object_id == [specific post/page ID]) : 
    ?>

    [your custom metatags]

    <?php else: ?>

    [standard metatags if hardcoded, otherwise, include php function to render wordpress theme generated ones]

    <?php endif; ?>
<?php endif; ?>

For more info regarding:

  • Hi can you tell me if I did this right? echo '<meta property="og:title" content="'do_shortcode('[user_firstname]').'is ready to be a developer '"/>'; – Glenn Thornton Dec 18 '17 at 0:34
  • you need to concatenate / separate / distinguish your php do_shortcode from the echo/print command. Try: echo '<meta property="og:title" content ="' . do_shortcode('[user_firstname]') . ' is ready to be a developer "/>'; note the period/dot between content=" and do_shortcode – Anson W Han Dec 18 '17 at 1:54
  • Ok, tell me how my code looks now.. Is this correct? -- if (is_page('169'.'221')) { function insert_fb_in_head() { echo '<meta property="og:title" content ="' . do_shortcode('[user_firstname]') . ' is ready to be a developer "/>'; } } add_action( 'wp_head', 'insert_fb_in_head', 5 ); – Glenn Thornton Dec 18 '17 at 5:27
  • are you defining a function in your theme's functions.php? If so, the conditional should be in the function, not wrapping it. Also, is_page can only accept an array of mulitple values; assuming the numbers are IDs, you don't need to pass them in quotes. So, in order to check if the page id is either 169 or 221, you want is_page( array( 169, 221, 'management' ) – Anson W Han Dec 18 '17 at 5:37
  • Yes, Im actually using a simple theme function plugin that allows me to add functions without adding to original or child theme... What is the 'managament' for? Just a random placeholder? – Glenn Thornton Dec 18 '17 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.