# WordPress

## Getting Started

## Create a connection

1. Sign in to [OpenGraph+](/)
2. Go to your website's **Meta Tags** page
3. Create a new connection and copy your connection URL

Your connection URL looks like `https://$OGPLUS_KEY.ogplus.net`.

## Find your theme header

Open your theme's `header.php` file. You can find it at:

- **Appearance → Theme File Editor** → select `header.php`
- Or edit the file directly at `wp-content/themes/your-theme/header.php`

## Add Open Graph meta tags

Add the following inside the `<head>` tag in `header.php`:

```php
<head>
  <!-- ... other meta tags ... -->
  <meta property="og:title" content="<?= wp_title('', false) ?: get_bloginfo('name') ?>">
  <meta property="og:description" content="<?= is_singular() ? wp_trim_words(get_the_excerpt(), 30) : get_bloginfo('description') ?>">
  <meta property="og:url" content="<?= esc_url(home_url($_SERVER['REQUEST_URI'])) ?>">
  <meta property="og:site_name" content="<?= get_bloginfo('name') ?>">
  <meta property="og:type" content="<?= is_singular() ? 'article' : 'website' ?>">
  <meta property="og:image" content="https://$OGPLUS_KEY.ogplus.net<?= $_SERVER['REQUEST_URI'] ?>">
  <meta name="twitter:card" content="summary_large_image">
</head>
```

Replace `https://$OGPLUS_KEY.ogplus.net` with your actual connection URL.

### Tag reference

| Tag | Value | Source |
|-----|-------|--------|
| `og:title` | Current page/post title, falls back to site name | `wp_title()` / `get_bloginfo('name')` |
| `og:description` | Post excerpt (trimmed to 30 words) or site tagline | `get_the_excerpt()` / `get_bloginfo('description')` |
| `og:url` | Full canonical URL of the current page | `home_url()` + `$_SERVER['REQUEST_URI']` |
| `og:site_name` | Your WordPress site name | `get_bloginfo('name')` |
| `og:type` | `article` for posts/pages, `website` for archives/home | `is_singular()` |
| `og:image` | Dynamic social card image from OpenGraph+ | Connection URL + page path |
| `twitter:card` | Always `summary_large_image` for large preview cards | Static value |

## What each function does

- **`wp_title('', false)`** - returns the current page or post title without echoing it
- **`get_the_excerpt()`** - returns the post excerpt, or auto-generates one from the content
- **`wp_trim_words()`** - trims text to a word count (30 words keeps descriptions concise)
- **`is_singular()`** - returns true on single posts and pages, used to set `og:type` to `article`
- **`home_url()` + `$_SERVER['REQUEST_URI']`** - builds the full canonical URL
- **`get_bloginfo('name')`** - your site name from Settings → General
- **`get_bloginfo('description')`** - your site tagline from Settings → General

## Child theme recommended

If you're using a third-party theme, create a [child theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/) first so your changes survive theme updates.

## Remove conflicting plugins

SEO plugins like Yoast, All in One SEO, and RankMath set their own Open Graph tags. If you have one installed, you may get duplicate meta tags. Either:

- Disable the social/Open Graph feature in your SEO plugin
- Add the OpenGraph+ meta tags through the plugin's custom meta tag feature instead

## Verify

Open the preview tool in your OpenGraph+ dashboard and paste a URL from your site. View your page source and confirm all Open Graph meta tags are present with correct values.


## Customize

OpenGraph+ captures your page in a headless browser and renders it as an image. You control what gets captured using meta tags in your theme and CSS in your stylesheets.

All of the rendering options below are standard HTML meta tags and CSS, so they work the same regardless of framework. The [HTML, CSS, & HTTP guide](/docs/html-css) covers each one in detail. This page shows how to wire them into a WordPress site.

## Meta tags

Add these to your theme's `header.php` inside the `<head>` tag alongside your `og:image` tag. They're all optional.

```php
<head>
  <meta property="og:image" content="https://$OGPLUS_KEY.ogplus.net<?= $_SERVER['REQUEST_URI'] ?>">
  <meta name="twitter:card" content="summary_large_image">

  <!-- Render at 800px wide instead of the default -->
  <meta property="og:plus:viewport:width" content="800">

  <!-- Only capture this element instead of the full page -->
  <meta property="og:plus:selector" content=".post-header">

  <!-- Inject inline styles on the captured element -->
  <meta property="og:plus:style" content="padding: 60px; background: #0f172a; color: white;">
</head>
```

See the [Rendering](/docs/html-css/rendering) guide for what each meta tag does and how they interact.

## CSS styling

OpenGraph+ adds a `data-ogplus` attribute to your `<html>` element during capture. Use it in your stylesheets to hide navigation, adjust spacing, or restyle anything for the social card without affecting your actual site.

Add the following to your theme's `style.css` or via **Appearance > Customize > Additional CSS**:

```css
html[data-ogplus] {
  .site-header { display: none; }
  .site-footer { display: none; }
  .sidebar { display: none; }
  .entry-content { padding: 60px; }
}
```

If you're using Tailwind, there's a plugin that gives you `ogplus:` variants like `ogplus:hidden` and `ogplus-twitter:bg-sky-500`. See [CSS Styling](/docs/html-css/data-attributes) for plain CSS examples and [Tailwind setup](/docs/html-css/data-attributes#tailwind-css).

## Templates

For fully custom social card layouts that pull content from your page, use `<template>` elements. These let you build a completely different layout for screenshots without touching your visible page.

Add this to your theme's `header.php` or `footer.php`:

```html
<template id="ogplus">
  <div style="padding: 48px; background: #0f172a; color: white; height: 100%;">
    <h1 style="font-size: 48px;">
      ${document.querySelector('h1')?.textContent}
    </h1>
  </div>
</template>
```

See the [Templates](/docs/html-css/templates) guide for expression syntax, platform-specific templates, and full examples.

## Testing locally

The [Preview Bookmarklet](/docs/html-css/bookmarklet) sets the `data-ogplus` attribute in your browser so you can see how your CSS and Tailwind variants look without deploying or waiting for a real crawler to hit your page.

## Full example

A theme header with all the pieces together:

```php
<head>
  <meta property="og:title" content="<?= wp_title('', false) ?: get_bloginfo('name') ?>">
  <meta property="og:description" content="<?= is_singular() ? wp_trim_words(get_the_excerpt(), 30) : get_bloginfo('description') ?>">
  <meta property="og:image" content="https://$OGPLUS_KEY.ogplus.net<?= $_SERVER['REQUEST_URI'] ?>">
  <meta name="twitter:card" content="summary_large_image">
  <meta property="og:plus:selector" content=".post-header">
  <meta property="og:plus:style" content="padding: 60px; background-color: #0f172a; color: white;">
  <meta property="og:plus:viewport:width" content="800">
</head>
```


## Troubleshooting

Something not working? Here are the most common issues and how to fix them.

## Meta tags not appearing

Make sure you edited the correct `header.php`. If you're using a page builder or Full Site Editor, the theme may not use `header.php` at all. In that case, add meta tags via a plugin or the theme's custom code section instead.

**Check:** View your page source, not DevTools. Page source shows what crawlers see.

## Duplicate og:image tags

SEO plugins like Yoast, RankMath, and All in One SEO set their own `og:image` tags. Disable the social image feature in those plugins, or use the plugin's API to override with the OpenGraph+ URL.

## Wrong image showing

This is almost always a caching issue. WordPress caching plugins cache the HTML output.

1. Purge your WordPress cache first
2. Open the preview tool in your OpenGraph+ dashboard
3. If the image is still stale, purge it from the dashboard
4. Re-check with the preview tool

## PHP errors

Ensure `<?= ?>` short tags are enabled (they are by default in PHP 5.4+). If you see raw `<?= $_SERVER['REQUEST_URI'] ?>` in your page source, use the long form instead:

```php
<meta property="og:image" content="https://$OGPLUS_KEY.ogplus.net<?php echo $_SERVER['REQUEST_URI']; ?>">
```

## Social platforms not updating

Twitter, LinkedIn, and Slack cache images aggressively on their end. After confirming the correct image appears in the OpenGraph+ preview tool:

- **Twitter:** Use the [Card Validator](https://cards-dev.twitter.com/validator) to force a refresh
- **LinkedIn:** Use the [Post Inspector](https://www.linkedin.com/post-inspector/) to clear their cache
- **Facebook:** Use the [Sharing Debugger](https://developers.facebook.com/tools/debug/) to scrape again

This is platform-side caching that OpenGraph+ cannot control.

## Purging cached images

1. Go to your website dashboard in OpenGraph+
2. Find the page you want to refresh
3. Click purge to clear the cached image

The next request from a social platform will trigger a fresh render.

## Testing

Use the preview tool in your OpenGraph+ dashboard to verify your setup before sharing URLs. This shows you exactly what social platforms will see.

