Tech Tag: Cocoon

  • Cocoon 2.8.4 introduces a beta feature that automatically generates featured images from post titles

    Cocoon 2.8.4 introduces a beta feature that automatically generates featured images from post titles

    Cocoon 2.8.4 introduces a beta feature that automatically generates featured images from post titles. To enable it, go to “Cocoon Settings” > “Editor” tab and activate the option. When creating a post, check the box to generate the featured image, and it will be created upon publishing or saving. If you change the title or author name, the image will regenerate, but long titles may be truncated.

    This feature also generates OGP and Twitter Card images automatically. You can customize the background, text, and border colors using filter hooks. However, as this is a beta feature, future changes to its functionality are possible.

    in ,
  • [Cocoon] Display a custom taxonomy if the currently displayed custom post type post has a custom taxonomy.

    [Cocoon] Display a custom taxonomy if the currently displayed custom post type post has a custom taxonomy.

    Cocoon uses nesting as a PHP structure, so it won’t work if you just modify single.php. First, copy single.php in the parent theme, place it in the child theme, change the file name to single-custom-post-type-name.php, and edit the following parts of the content. This will separate the behavior for custom post types.

    <?php //Post page content
    cocoon_template_part('tmp/single-contents-Custom-post-type-name'); ?>

    After that, create a folder called tmp in the child theme, duplicate the parent theme’s single-contents.php, place it in the child theme’s tmp folder, name it single-contents-custom-post-type-name.php, edit the following parts of the content. This is also one of the mechanisms to separate the behavior for custom post types.

    <?php //Body template
    cocoon_template_part('tmp/content-Custom-post-type-name') ?>

    After that, copy the parent theme’s content.php, place it in the child theme’s tmp folder, name it content-custom-post-type-name.php, and add the following part anywhere.

    <?php //Custom taxonomy categories/tags below the main text
            $post_type = get_post_type();
            $taxonomies = get_object_taxonomies($post_type, 'objects');
    
            $has_terms = false;
    
            if (!empty($taxonomies)) {
              foreach ($taxonomies as $taxonomy) {
                $terms = get_the_terms(get_the_ID(), $taxonomy->name);
                if ($terms && !is_wp_error($terms)) {
                  $has_terms = true;
                  // Show taxonomy name
                  echo '<h3>' . esc_html($taxonomy->label) . '</h3>';
                  echo '<ul>';
                  foreach ($terms as $term) {
                    $term_link = get_term_link($term);
                    if (!is_wp_error($term_link)) {
                      echo '<li><a href="' . esc_url($term_link) . '">' . esc_html($term->name) . '</a></li>';
                    } else {
                      echo '<li>' . esc_html($term->name) . '</li>';
                    }
                  }
                  echo '</ul>';
                }
              }
            }
            ?>

    By the way, I decided to put the above code directly below the code below.

    <?php //Categories/tags below the main text
            if (is_category_tag_display_position_content_bottom() && is_single()) {
              cocoon_template_part('tmp/categories-tags');
            } ?>
    in ,
  • [XServer] Key points for speeding up your WordPress site

    [XServer] Key points for speeding up your WordPress site

    When using Xserver, the Cocoon theme, and the W3 Total Cache plugin, it’s important to be mindful of overlapping optimization settings to avoid errors like 503 or 500. Here are some key points to consider:

    (more…)
    in ,
  • WordPress VS Ghost.org: Pagespeed

    WordPress VS Ghost.org: Pagespeed

    People were telling me that Ghost.org is way faster than WordPress.

    So I had to try it myself.

    I optimized my WordPress page, and also created a ghost.org page, and put both of them on Pagespeed Insights.

    And guess what?

    (more…)
    in ,