• This is what I need (without plugins and without adding shortcodes to all posts)

    Headings h1-h6. Collect lower headings and text. Example:

    [link to file removed]

    Must be opened with Microsoft Office to see the collapsible heading
    Any help is appreciated.

    • This topic was modified 2 years, 2 months ago by hamed.
    • This topic was modified 2 years, 2 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
    • This topic was modified 2 years, 2 months ago by Steven Stern (sterndata). Reason: removed link to hosted doc
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    @gjbyrjyy I removed the link; please DO NOT post word documents or other files and ask people to download them.

    YOu wrote “This is what I need (without plugins”. Sorry, but you’ll need a plugin if you want collapsible headers. (I assume that’s what you mean by “collect”).

    Here’s some plugins you can look at: https://wordpress.org/plugins/search/collapse+header

    or some blocks:
    https://wordpress.org/plugins/browse/blocks/

    This is not a core feature so it requires a plugin, whether you write it yourself or use one from the repository.

    Thread Starter hamed

    (@gjbyrjyy)

    Thanks for your reply

    I spent all my day on this subject.

    Finally, I installed the plugin, and with this code I was able to paste the shortcode of the plugin before and after the content in a single post.

    But what I need is: to add the shortcode after and before the heading tags (h1-h6).

    // This particular example adds Hustle Social Sharing shortcode after content without editing template files on single posts/pages only.
    
    function jmorris_before_after($content) {
    	    $beforecontent = '[expand title="A Long Time Ago" tag="h2"]';
    	    if ( is_single() ) {
    	    	$aftercontent = '[/expand]';
    	    } else {
    	    	$aftercontent = '';
    	    }
    	    $fullcontent = $beforecontent . $content . $aftercontent;
    	    
    	    return $fullcontent;
    }
    add_filter('the_content', 'jmorris_before_after');

    With respect

    • This reply was modified 2 years, 2 months ago by hamed.
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Please contact the plugin’s devs if you need help using it. Which plugin?

    Thread Starter hamed

    (@gjbyrjyy)

    Thanks for your reply

    The plugin has no problem and generates shortcodes.
    But I do not want to use 2 shortcodes for each tag (h1-h6) in posts (for heading collapse)
    That’s why I want to get help from php trick.
    My request: How to add any shortcode to before and after html tags (h1-h6).

    Thanks

    • This reply was modified 2 years, 2 months ago by hamed.
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    I don’t see that that code you pasted does that. And, if you’re editing $content in the_content() filter then you’d use strreplace callls.
    So, given you have $content, you’d scan for “<h” (case insensitive) and change it to “[whatever]<h”. The trick is to scan for the closing > and add a “[/whatever]” afterwards. That’s probably best done with a regex, which I am awful at.

    If you’re not a good PHP programmer, you probably want to hire one to write this plugin for you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to collect heading tag in a single post, such as Microsoft Word?’ is closed to new replies.