Function set default image when image not present

You’d want to put the <img/> tag and all the necessary content for the default image after the final colon in the following line: $my_image = ( $image[0] != ” ) ? ‘ <img alt=”‘ . esc_attr( sprintf( the_title_attribute( ‘echo=0’ ) ) ) . ‘” title=”‘ . esc_attr( sprintf( the_title_attribute( ‘echo=0’ ) ) ) . … Read more

How to get specific image in media library with php

There’s a few functions: wp_get_attachment_image_url( $attachment_id, $size ) – Gets the URL to specified size of the image. wp_get_attachment_image_src( $attachment_id, $size ) – Gets an array of the image URL, width, and height for the specified size of the image. wp_get_attachment_image( $attachment_id, $size ) – Gets the full HTML for an image, including width, height, … Read more

Adding to fontawesome-webfont.woff2 to boost website speed

If your theme is any good it will use wp_enqueue_style to include fonts in the head of your site. This gives you access to the style_loader_tag filter, which you can use to modify the html of the font link. Like this: add_filter( ‘style_loader_tag’,’wpse366869_preload_styles’, 10, 4 ); function wpse366869_preload_styles( $html, $handle, $href, $media ) { // … Read more

Replace word in “the_content” only for index.php

Few possibilities here: In index.php you find the_content() and replace it with: $content = get_the_content( $more_link_text, $strip_teaser ); $content = apply_filters( ‘the_content’, $content ); $content = str_replace( ‘]]>’, ‘]]&gt;’, $content ); $replace = array( ‘autoplay=””‘ => ” ); $text = str_replace(array_keys($replace), $replace, $text); echo $text; Did you try putting that bit of code in index.php? … Read more

Add icon/badge next to posttitle of specific category

This will depend on how your theme is structuring the templates for single.php (individual post view) but I’ll show you what to look for and how to apply via CSS. So from a theme I’m working on, this is where the category gets included in the post: <article id=”post-3417″ class=”post-3417 post type-post status-publish format-standard hentry … Read more

Display first name of logged in user?

The issue here is that both the functions have the same name – colaborator_avatar(). Make sure that $new_user contains the current user. Else use get_current_user_id() like this: get_user_meta( get_current_user_id(), ‘first_name’, true ); Show avatar and first name: // show user avatar if logged in function colaborator_avatar($atts) { if (is_user_logged_in() && !is_feed()) { return get_avatar(get_the_author_meta( ‘user_email’ … Read more

Uppercase first sentence in every post

Welcome to WPSE. So I can’t write all the code for you, but I would suggest you look at these main pieces, and then come back here or make new questions if you have followup questions: To alter the content of a post before it’s printed to the screen you could use the the_content filter. … Read more