• Resolved agg2

    (@agg2)


    Regarding:
    <?php echo get_secondary_title(); ?>

    The actual secondary title it produces on my website is “<i class=”fa fa-wrench” aria-hidden=”true”></i>” which is supposed to be parsed and rendered into an icon (see Awesome Fonts project).

    But when the secondary title is displayed (with Auto Show = off), it is unparsed/unrendered. How should I modify my PHP to allow “<i class=”fa fa-wrench” aria-hidden=”true”></i>” to be parsed and rendered into an icon in the secondary title?

    (Please note I’m PHP illiterate so please be explicit and unassuming in your answer.)

    • This topic was modified 7 years, 3 months ago by agg2.
    • This topic was modified 7 years, 3 months ago by agg2.
    • This topic was modified 7 years, 3 months ago by agg2.
    • This topic was modified 7 years, 3 months ago by agg2.
    • This topic was modified 7 years, 3 months ago by agg2.
    • This topic was modified 7 years, 3 months ago by agg2.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author thaikolja

    (@thaikolja)

    Hi @agg2,

    Well, then let’s render that thing ?? The PHP function htmlspecialchars_decode will do the trick. Here’s a simple commented example:

    /** The target post, in this example just a hardcoded ID */
    $post_id = 1;
    
    /** Get the original and unrendered secondary title of that post */
    $secondary_title = get_secondary_title(1);
    
    /** Decode it */
    $secondary_title_rendered = htmlspecialchars_decode($secondary_title);
    
    /** Do with it whatever you like */
    echo $secondary_title_rendered;

    If you’d like this behaviour to apply to all outputs of get_secondary_title, use the appropriate filter to modify the output:

    /**
     * @param $original_secondary_title
     *
     * @return string
     */
    function secondary_title_filter_html_output($original_secondary_title) {
             $secondary_title_rendered = 
             htmlspecialchars_decode($original_secondary_title);
    
             return $secondary_title_rendered;
    }
    
    add_filter("get_secondary_title", "secondary_title_filter_html_output");

    Please let me know if it works for you.

    • This reply was modified 7 years, 3 months ago by thaikolja.
    • This reply was modified 7 years, 3 months ago by thaikolja.
    • This reply was modified 7 years, 3 months ago by thaikolja.
    • This reply was modified 7 years, 3 months ago by thaikolja.
    Thread Starter agg2

    (@agg2)

    Wow thanks for such an explicit answer!

    Great plugin.

    My issue is that in the longer term, I won’t always be here to do something like that and my other administrators are really PHP-phobic and such a solution would need to be incorporated into the plugin user interface itself, as none of the other website administrators will go anywhere near code. Perhaps you would consider incorporating a toggleable option in future versions of the plug-in?

    Much obliged for the great work.

    Plugin Author thaikolja

    (@thaikolja)

    Perhaps you would consider incorporating a toggleable option in future versions of the plug-in?

    I had thought about this earlier but decided not to add it since people who use the PHP function of the plugin usually don’t mind adding another function around (in this case htmlspecialchars_decode). In titles, HTML is parsed properly. So, I’m not really sure if that option is necessary.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to handle html/shortcodes in secondary title’ is closed to new replies.