Get Post Primary Category

Here you go. Add this to functions.php and call it from anywhere you want. function get_post_primary_category($post_id, $term=’category’, $return_all_categories=false){ $return = array(); if (class_exists(‘WPSEO_Primary_Term’)){ // Show Primary category by Yoast if it is enabled & set $wpseo_primary_term = new WPSEO_Primary_Term( $term, $post_id ); $primary_term = get_term($wpseo_primary_term->get_primary_term()); if (!is_wp_error($primary_term)){ $return[‘primary_category’] = $primary_term; } } if (empty($return[‘primary_category’]) || … Read more

Slide in Panel WordPress Post

The reason why your query fails is the following. You are finishing the loop before your cd-panel with <?php endwhile; wp_reset_postdata(); ?> which is correct. However, after that you are simply using <?php the_title(); ?>, <?php the_content(); ?> which is just a single template tag, and in your case, outputs the title of the first … Read more

Write text below a specific part of a sentence

Maybe you could find the x/y-position of the span with Javascript and position another div with an increased y-position? I don’t think there will be an out-of-the box css solution to this problem. Here is a quick example: <!DOCTYPE html> <html lang=”en”> <head> <meta name=”viewport” content=”width=device-width” /> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /> <style> p {font-size: … Read more

How can you limit srcset on a single type of page?

Here’s an example for filtering out sizes above set limit from the srcset attribute on certain post type. This works for featured image and images added to the post content with Gutenberg. (Tested on Twenty Twenty theme). function filter_wp_calculate_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) { global $post; if ( $post && ‘post’ === $post->post_type … Read more

How to make a custom field as an editor in wordpress?

Naren, The actual set-up for the classic/TinyMCE editor is relatively straightforward, I have updated your wordpress_register_fields() function with the necessary lines. For wp_editor() to work you need to get the content if there’s any saved, id the field and then provide settings arguments. (https://developer.wordpress.org/reference/functions/wp_editor/) function wordpress_register_fields() { global $post; // Nonce field to validate form … Read more

Adding HTML to the Header, Screws up in IE7

Write a stylesheet just for ie7 and link it in wordpress like so: <!–[if IE 7]><link rel=”stylesheet” type=”text/css” href=”https://wordpress.stackexchange.com/questions/4324/<?php bloginfo(“stylesheet_directory’); ?>/css/ie7.css” /><![endif]–> in the file add this #header table {float:right;} #header table tr td p {margin-top:45px;}

Switching From HTML to Visual Editor and Back Completely Strips Page Contents

I’ve had this code in a custom local plugin for a while. Or you could just stick it in your theme’s functions.php: // Allow iframe in TinyMCE function tinymce_add_iframe( $arr = array() ) { $extra=”iframe[id|class|title|style|align|frameborder|height|longdesc|marginheight|marginwidth|name|scrolling|src|width]”; if ( isset( $arr[‘extended_valid_elements’] ) ) { // append to existing value $arr[‘extended_valid_elements’] .= ‘,’ . $extra; } else { … Read more

How to prevent pages from automatically adding line breaks?

Try using get_the_content(); in your page template loop instead of the_content(); EDIT 05/24/2012 – Try this: <div id=”main-content”> <?php while( have_posts() ) : the_post() ?> <h1 id=”pagetitle”><?php the_title(); ?></h1> <div class=”pagecontent”> <?php echo get_the_content(); ?> </div> <?php endwhile ?> </div> P.S. You will also need to consider the rest of your more “normal” wordpress pages … Read more