Skip to content

Instantly share code, notes, and snippets.

@morgyface
morgyface / wp_meta_description_function.php
Last active March 10, 2020 18:25
WordPress | Function | Use post/page excerpt to generate meta description for SEO
<?php
// Generating a meta description using standard WP components
function meta_description( $char_limit ) {
$tagline = get_bloginfo ( 'description' );
$post_object = get_post();
$excerpt = $post_object->post_excerpt; // Get the raw excerpt, warts (tags) and all.
$content = $post_object->post_content; // Get the raw content.
if ( !empty( $excerpt ) ) { // If there is an excerpt lets use it to generate a meta description
$excerpt_stripped = strip_tags( $excerpt ); // Remove any tags using the PHP function strip_tags.
$excerpt_length = strlen( $excerpt_stripped ); // Now lets count the characters
@ahmadawais
ahmadawais / aa_URLtoAttachmentID.php
Created August 16, 2014 12:06
Get the Attachment ID from an Image URL in WordPress
function pn_get_attachment_id_from_url( $attachment_url = '' ) {
global $wpdb;
$attachment_id = false;
// If there is no url, return.
if ( '' == $attachment_url )
return;
// Get the upload directory paths