• Resolved shopandstore

    (@shopandstore)


    hello,
    in wp-includes>formating.php
    i need to add function, but i wish this funtion should be for posts, not for pages. how to make this?

    function sanitize_title_with_dashes($title) {
    blablabla……….
    }…………………….

Viewing 10 replies - 1 through 10 (of 10 total)
  • esmi

    (@esmi)

    Try something like:

    function foobar() {
    global $post;
    if( $post->post_type == 'post' ):
    [...]
    endif;
    }
    Thread Starter shopandstore

    (@shopandstore)

    hoh, thanks !!

    sory, i meant not theme>functions.php , but wp-includes> formating.php

    esmi

    (@esmi)

    Never, ever, edit core WordPress files. What is it that you are trying to do?

    Thread Starter shopandstore

    (@shopandstore)

    yes, i know that, but only i want, if you can give me the correct coding, because i can’t get the correct value. in formatting i want:

    IF it is page’s area, then i want the following function to be used:
    function sanitize_title_with_dashes($title) {BBBBBBBBBBBBBBBBB}

    IF it is post‘s area, then i want the following function to be used:
    function sanitize_title_with_dashes($title) {AAAAAAAAAAAAA}

    can you help in this?

    esmi

    (@esmi)

    Erm, both scenarios above are the same – as is the function that you are trying to use.

    Thread Starter shopandstore

    (@shopandstore)

    hoh.. what is going to me?… i’ve mistaken again.

    IF it is page’s area, ..
    IF it is Post‘s area, …

    esmi

    (@esmi)

    Can you elaborate? What exactly do you want to happen to the title if it is a Page? And if it is a Post?

    Thread Starter shopandstore

    (@shopandstore)

    If it’s a page, then the following function to be used:

    function sanitize_title_with_dashes($title) {
    $title = preg_replace(‘XX’, ‘HELLO‘, $title);
    return $title;
    }

    If it’s a post, then the following function to be used:
    function sanitize_title_with_dashes($title) {
    $title = preg_replace(‘XX’, ‘GOOD BY‘, $title);
    return $title;
    }

    esmi, thanks so much for your help!

    esmi

    (@esmi)

    Your best option would be to stop using the_title() or get_the_title() in your theme’s template files but to use $post->post_title instead. Then use your own sanitize function based on $post->post_type.

    Thread Starter shopandstore

    (@shopandstore)

    i can find and edit everything, if you have shown me a simple “if, then”, then i could understand, but I’m not skilled in programming, so it’s a hard for me how to edit the code exactly..

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Is there any way to add funciton only to Posts’ is closed to new replies.