Post Thumbnail URL CPT

User
has post thumbnail full url single cpt
Assistant
If you're looking to retrieve the full URL of the post thumbnail (featured image) for a single Custom Post Type (CPT) in WordPress, you can use the following code:

if ( has_post_thumbnail() ) {
    $thumbnail_url = get_the_post_thumbnail_url( get_the_ID(), 'full' );
    echo '<img src="' . esc_url( $thumbnail_url ) . '" alt="' . esc_attr( get_the_title() ) . '">';
} else {
    echo 'No featured image set for this post.';
}

### Explanation:
1. **`has_post_thumbnail()`**: Checks if the current post has a featured image.
2. **`get_the_post_thumbnail_url()`**: Retrieves the URL of the featured image. The `full` parameter ensures that you get the full-size image URL.
3. **`get_the_ID()`**: Gets the ID of the current post.
4. **`esc_url()` and `esc_attr()`**: Escapes the URL and the title for safe output.

### Usage:
– Place the code inside the WordPress loop for your Custom Post Type template (e.g., `single-{cpt}.php`).
– Replace `{cpt}` with the slug of your Custom Post Type.

Let me know if you need further assistance!

User
get stylesheet direcory uri
Assistant
To get the URI of your WordPress theme's stylesheet directory, you can use the `get_stylesheet_directory_uri()` function. Here's how you can use it:

$stylesheet_directory_uri = get_stylesheet_directory_uri();
echo $stylesheet_directory_uri;

### Explanation:
– **`get_stylesheet_directory_uri()`**: Retrieves the URL of the current theme's directory. If you're using a child theme, this will return the child theme's directory URL.
– It is different from `get_template_directory_uri()`, which always returns the URL of the parent theme's directory.

### Example Usage:
If you want to include a CSS file located in your theme's directory, you can use this function as follows:

echo '<link rel="stylesheet" href="' . esc_url( get_stylesheet_directory_uri() . '/style.css' ) . '">';

This will output the link to the `style.css` file in your theme's directory.

Let me know if you have specific use cases or further questions!

Leave a Comment

Your email address will not be published. Required fields are marked *