• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How to do Drop Caps in a Genesis child theme

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to do Drop Caps in a Genesis child theme

This topic is: not resolved

Tagged: child theme, css, Drop Caps, genesis

  • This topic has 3 replies, 2 voices, and was last updated 4 years, 11 months ago by Victor Font.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • April 22, 2018 at 4:45 am #219178
    baggi-t
    Participant

    I'm working on a Genesis child theme and by using the selector: .entry-content > p:first-child:first-letter I'm able to set the first character in each post and excerpt to be a drop cap. However, if there is a photo in the post with its html appear in the entry-content div before the the p:first-child, I lose the drop cap. How do I modify my selector to target the p:first-child after the img+caption html?

    Many thanks
    Tim

    http://timbaggaley.com
    April 23, 2018 at 12:33 am #219186
    Victor Font
    Moderator

    Instead of trying to calculate the first paragraph, why not just add a class to the first paragraph. Using the WordPress editor's text tab, include class="drop-cap" to the paragraph tag. This is the way Gutenberg does it:

    HTML:
    <p class="has-drop-cap">

    CSS:

    p.has-drop-cap:first-letter {
     float:left;
     font-size:4.1em;
     line-height:.7;
     font-family:serif;
     font-weight:600;
     margin:.07em .23em 0 0;
     text-transform:uppercase;
     font-style:normal
    }
    p.has-drop-cap:not(:focus) {
     overflow:hidden
    }

    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    April 23, 2018 at 7:12 am #219193
    baggi-t
    Participant

    Sorry, can't get this to work. I've added the class to to the first para using php in my functions.php.

    // Add class to first para
     function first_paragraph($content){
    	return preg_replace('/<p([^>]+)?>/', '<p$1 class="dropcap">', $content, 1);
    }
    add_filter('the_content', 'first_paragraph');

    Which works fine but is still thwarted if the first p has the html for an img ahead of it. How do I get my first p styling to apply after the img html?

    April 23, 2018 at 1:23 pm #219202
    Victor Font
    Moderator

    I don't understand why you want to use PHP to add a class. That's really a circuitous way to do it. Edit the HTML directly.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble