Need help in creating a wp plugin

Discussion in 'PHP' started by rahu_l_, Jan 7, 2014.

  1. #1
    Hello DP,

    i need to add few lines of php to single.php file present in the wordpress script via plugin..

    A wp plugin which will add few php codes to single.php file when activated ...

    can anyone help me ?
     
    rahu_l_, Jan 7, 2014 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    you shouldn't add lines of code to the file but rather use filters and hooks to add whatever you want.

    Can you give use more details about your plugin and what you are trying to achieve then we might be able to help further.
     
    stephan2307, Jan 8, 2014 IP
  3. rahu_l_

    rahu_l_ Well-Known Member

    Messages:
    535
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    175
    #3
    i have a website of url shorter, so i want to make a wp plugin, like when user activate it , then they will get a short url of each post via my api ..
     
    rahu_l_, Jan 8, 2014 IP
  4. Tanmoy S. Khan

    Tanmoy S. Khan Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    The best way should be wrap the code into shortcode as you're using WordPress. Plugin user can use the shortcode anyway in post content to display the short url. If you anything automatic, use filter.

    Normally plugin cannot modify theme's file by itself (though it's not impossible).
     
    Tanmoy S. Khan, Jan 13, 2014 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    Depending on what you want - the user getting a code when making a post, or the code / shorturl being present on the page when it's posted. The first is just making a short url and presenting it in the admin-panel where you write a post. The second involves adding the short url to the post, which can either be done by a shortcode, as suggested above, or a checkbox-setting in the admin-panel, which when checked adds a shorturl to the end of the post (for instance). This isn't very hard to do, just look up some "wordpress adding code automatically through selectors" or something similar.
     
    PoPSiCLe, Jan 15, 2014 IP