WordPress.org

Ready to get started?Download WordPress

Forums

How to insert some code BEFORE 1st image in every post? (7 posts)

  1. Alex Ben
    Member
    Posted 2 years ago #

    Can anyone help me how to insert some code BEFORE 1st image in every post? Is there any hack?

  2. Michael Bishop

    Posted 2 years ago #

    Can you be more specific what you want to insert? And how is the image being inserted?

  3. Alex Ben
    Member
    Posted 2 years ago #

    I would like to insert this code:

    <?php if ($is_hd) { ?>

    <fieldset id="hdswitch">
    <span>Choose:</span> <span><label for="px1024"><input id="px1024" type="radio" name="blogwidth" value="1024" checked="checked" /> 1024px</label></span>

    <span><label for="px1280"><input id="px1280" type="radio" name="blogwidth" value="1280" /> 1280px</label></span>
    </fieldset>

    <?php } ?>

    An Example:

    http://www.theatlantic.com/infocus/2012/04/space-shuttle-discoverys-final-flight/100281/

  4. Alex Ben
    Member
    Posted 2 years ago #

    > And how is the image being inserted?

    I have a lot of images in posts:
    <img style="padding: 0px; display: inline; title="title" border="0" alt="alt" src="http://site.com/content/2012/04/post_name/25.jpg" width="..." height="..." />

  5. Michael Bishop

    Posted 2 years ago #

    So you want to do it on the single.php, or in index.php?

    I'm just curious why you can't edit the templates.

  6. Alex Ben
    Member
    Posted 2 years ago #

    I want to do it on the single.php.
    But it is not possible to insert automatically the code above first image into single.php like this:
    http://dl.dropbox.com/u/24525697/10.jpg

    I suppose I should insert some hack into functions.php. Somesing like popular "How to: Get the first image from the post"

  7. Michael Bishop

    Posted 2 years ago #

    Certainly there are ways to parse the 1st attached image, and you could include your code in that function, but personally, I'd use the featured image for that and insert the code above the call for the featured image in single.php.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.